- Home /
Javascript error.. insert semicolon??
Hey, thank's for reading. I am currently making a script in Unity 5 with Javascript, and there is an error, and I cannot figure out what's wrong with my script.
Here's the error:
Assets/Standard Assets/HorrorGameStuffs/DreamshardsLab.js(27,26): UCE0001: ';' expected. Insert a semicolon at the end.
And here is the script:
var Dreamshard : int = 0;
var dreamshardsToWin : int = 2; //number to win!
var win = false;
function Start()
{
win = false;
}
//Saying if you have 'x' dreamshards, the 'win' state is applied.
function Update ()
{
if (Dreamshard == dreamshardsToWin)
{
win = true;
}
} //trying to say that if win state, then upon entering zone, next level loaded.
if (win == true)
{
function (OnTriggerEnter)
{
if (other.gameObject.tag == "ExitLab")
{
Application.loadedLevel("MainMenu");
}
} ***//Line 27***
}
function OnTriggerEnter( other : Collider )
{
if (other.gameObject.tag == "Dreamshard")
{
Dreamshard += 1;
Debug.Log("A dreamshard was picked up. Total shards = " + Dreamshard);
Destroy(other.gameObject);
}
}
function OnGUI()
{
if (Dreamshard < dreamshardsToWin)
{
GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "" + Dreamshard + " Dreamshards");
}
else
{
GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "Find the exit.");
}
}
When I double-click the error, it redirects me to line 27 (I've marked it for you). I honestly have no idea why it would want me to add a semicolon.. Please help. Thank you so much for your time.
Answer by Eno-Khaon · May 17, 2015 at 07:23 PM
Also, the formatting itself is a little wonky.
if (win == true)
{
function (OnTriggerEnter) // Not good
{
if (other.gameObject.tag == "ExitLab")
{
Application.loadedLevel("MainMenu");
}
}
}
Like tanoshimi stated, this block isn't contained within a function. Also, your line "function (OnTriggerEnter)" is a little confusing. You can remove that part and shove the rest into the OnTriggerEnter function.
function OnTriggerEnter( other : Collider )
{
if (other.gameObject.tag == "Dreamshard")
{
Dreamshard += 1;
Debug.Log("A dreamshard was picked up. Total shards = " + Dreamshard);
Destroy(other.gameObject);
}
if (win == true)
{
if (other.gameObject.tag == "ExitLab")
{
Application.loadedLevel("MainMenu");
}
}
}
Answer by tanoshimi · May 17, 2015 at 06:38 PM
Please indent your properly. When you do, you'll see that you have tried to define your OnTriggerEnter() function within a if(win == true) {} block.
Your answer
Follow this Question
Related Questions
Scripting error #2! 2 Answers
Incremental game need help 1 Answer
OnCollisionEnter2D not working? 2 Answers
Script error: OnTriggerEnter 1 Answer
Issue with OnTriggerEnter. 1 Answer