C# update code runs twice ?
Hello everyone,
i have an problem and can't figure out why it happens. When i run this code, the switch case prints me two numbers. The whole IF statement runs twice, but why? The manouverDone bool is only after the secoond run "false"... ( i figured that out with that debug line). I have also used a lock object for the bool, same result.
void Update () {
if (maneuverDone){
//Debug.Log("maneuverDone IF: "+maneuverDone);
maneuverDone = false;
nextManeuver = Random.Range(1,6);
switch (nextManeuver ){
case 5:
print ("5");
break;
case 4:
print ("4");
break;
case 3:
print ("3");
break;
case 2:
print ("2");
break;
case 1:
print ("1");
break;
default:
print ("Error");
break;
}
}
}
Answer by TruffelsAndOranges · Jul 12, 2015 at 12:40 PM
I don't see any problem with your code. My guess is that you have accidently added the your script to two different game objects.
Why are you using print instead of Debug.Log("...")?
You are right, oh man. To simple ... ><
Print, because i was to lazy and copied the switch case from the unity tut page. ;)
Thanks alot !!
No problemo. Glad I could help. :-) Good luck!
Your answer
Follow this Question
Related Questions
AudioSource in Update 1 Answer
Reducing an int "while" a bool is true 1 Answer
Timer onTriggerEnter doesn't launch 0 Answers
How do I check if bool is true from another script? 2 Answers
checking a bool via string 0 Answers