I have to scripts. One is The player's Health and the other one is Enemy script for the enemy. So basicly the enemy follows the player and collides, then the health has to be subtracted. __________
Anyone please help me with this, I want the enemy to subtract health from the player when the enemy collides with him.
asked Mar 13 '12 at 06:16 PM
You HEALTH variable is static. You should read about static variables as starters sometimes think static means accessible outside which is 1/2 true and 1/2 false.
In the enemy script add a function:
Now let's say you want to use SendMessage: in your player script:
in your enemy script:
What is does basically is like sending a message with a name on it (DecreaseHealth) and only the appropriate receiver is going to look at it.
Now to finish, as I already advised you, have a look at switch statement to make your script more efficient. if statements run one case after the other and continues if wrong.A switch does not rely on previous cases, the program can re-organize to get the fastest execution.
answered Mar 16 '12 at 06:52 AM