- Home /
This question was
closed Jan 07, 2012 at 04:21 AM by
syclamoth for the following reason:
The question is answered, right answer was accepted
Question by
Grim420-2 · Dec 13, 2009 at 05:16 AM ·
syntax-errorbce0044
OnCollisionEnter - simple question
function OnCollisionEnter(collision:Collision)
{
if(collision.gameObject.tag == "Player");
{
Debug.Log("yay");
}
}
When I save this simple script, it gives me an error that says
expecting :, found ';'.
on the Debug line.
I have a similar script to test CharacterController hits, and it works just fine. Why does this happen? and What is the difference in detecting a collision from the CharacterController versus using an OnCollisionEnter function on a regular object?
Comment
Best Answer
Answer by Stelimar · Dec 13, 2009 at 05:20 AM
Try this:
function OnCollisionEnter(collision:Collision)
{
if(collision.gameObject.tag == "Player")
{
Debug.Log("yay");
}
}
You don't put a semi-colon after an if statement.
Our codes are identical.
I have no idea why its telling me to use a colon on that line.
At the end of the line with the if statement, remove the semi-colon (;)
Holy moly! Its amazing how the simplest things screw it all up. Thanks.