I have a script to change a variable when an object collides with an other certain object, but it is applying to all collisions that happen to it. Here is the code.
`function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == “MainChar” && Walking.runspeed > 8);
Walking.runspeed = Walking.runspeed - 7;
yield WaitForSeconds (waittime);
Walking.runspeed = Walking.runspeed + 7;
}`
Semi-colon after the if shouldn’t be there. If you get a chance, this is the sort of thing any so-so intro programming book will cover. I’ve had people say the “Head First” books aren’t bad. The rules for ifs are pretty much the same for all languages:
if( ... ) // <-- no semi-colon
{ // <- curlybrace marks start of if code
...
} // <- close curly marks end of if code
You think, “but wait, semicolons go at the end of all statements.” The thing is, the IF isn’t done yet. A semi-colon says “if this is true…nevermind.” Then the stuff you meant to be in the if, becomes just normal “do all the time” code.
Likewise, the code inside needs curly-braces. When the computer sees “if(A) then B; C;” it can’t tell whether C is part of the if, or “now the if is done, keep going.” If you leave out the {}'s, the computer just guesses you meant to have them around only B.