- Home /
Problems with count++?
Hello gentlemen well I have some troubles counting an event:
var eventCount: int = 0;
if(Player.transform.position.y < - 5){
eventCount++;
}
If my player falls to -5, my variable eventCount its suposed to go up to 1 but it goes to 2.
Any ideas on how to solve that?
Answer by Joshua · Apr 10, 2011 at 11:32 PM
Add a timeout before it can add again?
Sorry if I sounded a little sarcastic. It's a genuine suggestion though. Also, you're not providing information about how/when the position is set to be higher then -5 again, so I can't say if this happens in a single frame or not.
Answer by user-11398 · Apr 10, 2011 at 11:58 PM
It is a little difficult to ascertain what you want from that section of code.
Unless you are processing the event instantly the eventCount will increment every frame that your transform position is less than -5... that could be 1000 times a second. So as Joshua answered, adding a timeout before you can increment eventCount again will probably fix your issue.
Answer by NewfieJoe · Apr 11, 2011 at 04:34 AM
Also I don't know if it was a typo in your question or an unnoticed error in your code but:
var eventount: int = 0;
should be
var eventCount: int = 0;
It is just an unoticed error but that doesnt matter, this is just the name of the variable.
Your answer
Follow this Question
Related Questions
Counting on Unity iphone. 1 Answer
Calc tris and verts pr. frame in webplayer 1 Answer
Keeping track of how many times games as been Restarted 0 Answers
make it create GUI copy per count. 0 Answers