I cant seem to figure out how to write the code. Maybe I am going about this the wrong way but… I’m trying to subtract 1 from my player lives when the objects with tag “kill” are Destroyed. Is this possible?
thats no problem.
In the function that handels the destruction of the object, just reduce the variable on the corresponding component by 1
I’m not sure what you mean. Here is my code…
function Update () {
if(transform.position.y <= 0.3){
Destroy(gameObject);
}
}
No offense, Unk, but if you aren’t sure what someone means by decrementing a variable then you’re in a bit over your head. Do yourself a world of good and go find a decent ‘programming for beginners’ book or course on the web.
Well douch I understand what he means. I’m just not sure how to write the code and I don’t think that will work any way. I cant declare the variable on the same object that is to be destroyed and then try to subtract 1 from that.
Look at the answer you received in your earlier thread:
That is, create an empty game object separate from your player. Attach a script to this which records the player lives. Reference the manager game object in your player script by creating a variable to hold it, then drag the game object to the appropriate spot in the inspector.
The script attached to the game manager will look something like this:
var playerLives : int = 20;
Then in your player script:
var manager : GameObject;
function Update () {
if(transform.position.y <= 0.3) {
manager.playerLives--;
Destroy(gameObject);
}
}
Does that make sense?
Thank you so much ill try that