- Home /
" ';' expected. Insert a semicolon at the end." Error Help
Hi. I am making an iOS game, and for some reason, Unity3d is saying I need a semicolon when there is actually one there. Here is the code:
//Script to revert winning player back to main menu
var levelToLoad : String;
function OnTriggerEnter(hit : Collider)
{
if (other.gameObject.name == "Player")
then Application.LoadLevel(levelToLoad);
}
//END FUNCTION ONTRIGGERENTER
It says I need a semicolon on lines 8,7. Please help!
Answer by robertbu · Mar 20, 2014 at 08:07 PM
You don't use 'then' in Javascript, so you need to remove it on line 8. You've not declared 'other'. Usually that is the name of the collider passed in. Also a collider inherits the 'name' variable, so you don't have to redirect through 'gameObject'. Putting the changes together:
var levelToLoad : String;
function OnTriggerEnter(other : Collider)
{
if (other.name == "Player")
Application.LoadLevel(levelToLoad);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Insert semicolon at the end when theres already one? 0 Answers
Error in distance coding 1 Answer
UCE0001 error Insert a Semicolon at end 1 Answer
BCE0044: expecting }, found 'private'. PLEASE HELP!!!!! 2 Answers