Hey guys. I wrote a script and when I try to run it it says I need a semicolon but I can’t figure out where. Help?
function OnCollisionEnter (Collision) {
If(Collision.gameObject.tag == "Rock"){
Destroy (gameObject, 1);
}
If(Collision.gameObject.tag == "Rock"){
Destroy (gameObject, 1);
}
}
You haven’t set up the variable in OnCollisionEnter correctly. Collision is the class that stores info on collisions, but you need to have a variable to access it.
function OnCollisionEnter (hit : Collision)
{
print (hit.gameObject.name);
}
That doesn’t help. The problem was that I need a semicolon and I can’t figure out where.
Maybe post the rest of your code for the entire script. Errors like those tend to be elsewhere in the code.
Sometimes it’s not even about missing a semi-colon: if you have invalid syntax elsewhere, the compiler can mix things up.
That is the whole code. I figured it out though.
The reason I pointed out your problem with Collision is because, as Jtman562 said, often and error message that seems simple can be caused by something in an entirely different part of the script. Fixing fundamental errors like the one you had often makes those error messages disappear. As you work with Unity and Unitron more, you’ll see what we mean. Glad you found the problem, though.