- Home /
Can't change variables on collision, if statement being ignored
Figured it out, there was an extraneous "var" in my code throwing stuff off.
So, to confirm what you're saying, you've debugged and you're sure that the collision gameObject is either flag or flagStand, so the code is entering the if-statements, right? And once it's confirmed it's either flag or flagStand, nothing changes within the if-statements?
I don't know if it's entering the certain if statements. For example, it could be ignoring "if(theCollision.gameObject == flagstand){" and/or "if(flagHeld == true){" entirely because it never destroys the flag or prints anything.
On the other hand, everything EXCEPT for "var flagHeld = true;" is working under "if(theCollision.gameObject == flag){". This is a running problem, I haven't been able to change variables on collision.
Finally, yes I have defined flagStand and flag correctly.
Just do some basic Debugging within each if-statement, just to see if it is at least entering them.
Also, since it can't be both flag and flagStand, you could make that an if/else if statement.
Answer by DaveA · Mar 24, 2012 at 09:33 PM
Are you sure you set both 'flag' and 'flagStand'? I would get into the debugger and make sure things are what you expect. Also I'm not sure checking for gameObject equality is the best way, esp since you Destroy flag. Why not use Tags?
Yes, they have both been set properly. How would you go ab out checking gameObject equality, as that is likely related to the problem?
You could look at the unique id (Object.GetInstanceID), or give each a unique name and test the name.
Your answer
Follow this Question
Related Questions
How do I create a variable for each GameObject that I added to an array by using a loop? 2 Answers
Trying to proceed to next level when multiple items have collided 1 Answer
Editing a variable from another script on collision 3 Answers
Accessing a variable in one script from another script? (using C#) 1 Answer
Getting a Trigger's parent 1 Answer