I have some troubles with shooting, so just checking if I am doing this right.
So player with controller should be attached shooting script that shoots and has lines to apply damage to hit objects. All the objects (enemies) have a script that sets their life and kind of a receiver that checks if damage is sent from shooting script and it applies damage then.
Or there are other ways to do this?
asked Feb 24 '10 at 03:41 PM
That is a good way to do it; the shooter sends out a raycast, and sends a message to whatever it hits which calls a function to apply damage (the enemy has a function to apply damage, which is called by the shooting script when it hits).
answered Feb 25 '10 at 01:19 AM
you can do this in many ways. you should create a shoot script for the player. for damage you can create a damage script for your bullet or attach the code to shoot script or create a damage script for enemies. having a damage script for bullets is the best approach because you can customize it for different bullets to have different types and amounts of damages. in your bullet you should check if you collide with the enemy or even you can check this in enemy. for example you can tag all of your bullet types with bullet tag and in Trigger functions of enemy check if the other collider has the bullet tag then get the others damage component and execute it's apply damage function. you can do these things in many ways. it's dependent to your project.
answered Feb 25 '10 at 05:18 AM