Hello,
In my game the player has 3 lives and when it collides with an object with the tag “avoid_me” it should lose 1 life, but instead it loses 2 lives per time, why does this happen? Here the codes (c#) :
I just removed Lives = PlayerPrefs.GetInt("Lives"); from the code and it works! I lose 1 life at a time…I suppose it was decreasing by 2 because I stored it 2 times, and the Lives-- was decreasing two times? hehe
Well, GetInt was retrieving it. Hm. lol I’m glad it’s solved. I had just mentioned that you could remove that, not even thinking it would solve your problem. Had to be something else
One more thing bro.
Now I am working on an object that increases the life of the player by 1 when the player collides with it (but it doesn’t feel like a “brick” because I use trigger). So the new script is :
In the case you touch an object with tag “avoid_me”, it all goes well, the player loses 1 life and the life text decreases by 1, but in the case a player collides with the “Life”, yes it gets a life, but why it doesn’t show?
For example, if I have 3 lives, I touch a “Life”, and then I go on an object with tag “avoid_me”, I have 3 lives. If I get 10 “Life”, and then I touch an object with “avoid_me”, I have 12 lives.
So it increases the lives but why it doesn’t display as when it loses lives? What’s wrong with the code?[/code]
Well, your posted code is incomplete. You must be setting the text somewhere when it’s updated (for losing a life).
You just need to add the same kind of text update when you gain a life.
One other thing – you could create a variable for the Text game object and connect it in the inspector. Use that variable to do your updates, rather than GameObject.Find, like you have written in UpdateUI.