|
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. __________ Health :
Enemy :
Anyone please help me with this, I want the enemy to subtract health from the player when the enemy collides with him.
(comments are locked)
|
|
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. Thanks, oh and it wasn't about the variable type - it's the name. So I changed it to Life instead of HEALTH, BTW the variable had to be changed to private. Thanks a lot!!!
Apr 06 '12 at 01:05 AM
BigBlob
(comments are locked)
|
|
Look at using a combination of OnCollisionEnter and SendMessage to achieve what you need. The second link is SendMessage http://unity3d.com/support/documentation/ScriptReference/GameObject.SendMessage.html
Mar 13 '12 at 06:29 PM
Meltdown
(comments are locked)
|
