- Home /
Simple syntax error that I can't seem to find
So I am using this script to travel between scenes, however it says that there are 3 errors with placing ;'s and }'s but i have already placed them, please help.
#pragma strict
var Scene : int = 0 ;
function OnCollisionEnter(my_collider : Collision)
{
if(my_collider.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.E));
{
Application.LoadLevel(Scene):
}
}
You can't put Get$$anonymous$$eyDown inside OnCollisionEnter, since it's unlikely that someone could press the key down during the same frame that the collision occurs. Also, use CompareTag when comparing tags ins$$anonymous$$d of using string comparisons (more efficient).
so what should I use ins$$anonymous$$d of OncollisionEnter? Or do you have any tips on how I should write this piece of code?
Answer by william9518 · Aug 17, 2013 at 09:25 PM
Lots of errors I can see :3. I will just type new code for u instead:
#pragma strict
var Scene : int = 0;
function OnCollisionEnter(my_collider : Collision){
if(my_collider.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.E))
{
Application.LoadLevel(Scene);
}
}
Please do try to use some formatting next time.
STUFF I EDITED:
Do not put a semicolon at the end of an if statement. That alone caused 3 errors because a semicolon ends a statement, but with if in front, so that is an error. Since it ends the statement, the curly brackets circling the if block are no longer part of the if, and are problems.
Thanks, I have no formal school and am currently learning by experimenting, Sorry.
Answer by IgorAherne · Aug 17, 2013 at 08:42 PM
substitute : with ; at line 10
I accidentally typed that here in the actual code it is a ; any other errors?
Your answer
Follow this Question
Related Questions
Script error with turrets 5 Answers
Syntax errors? 2 Answers
Javascript syntax errors with basic expressions 2 Answers
Cannot remove a prefab using OnCollisionEnter function. 1 Answer