I apologize if this is seems like a stupid question but coding is very new to me. I did a little searching and found some code that partially works for what I am trying to do but I cant get it all to work. I have this code all working except for subtracting from the playerLives. What am I do wrong?
var playerLives: int;
function Update () {
if(transform.position.y <= 0.3){
Destroy(gameObject);
playerLives --;
}
}
That makes no difference, since Destroy doesn’t take effect until the end of the current frame anyway. The problem is that you are destroying the object that playerLives is on, so naturally the script, along with the variable, won’t exist anymore.
I was thinking about it and I have a tag set on my object. Is there a way I can say if gameobject with tag " " is destroyed then subtract from playerLives?