- Home /
UnityScript coding error:
I have a simple project. When you enter a trigger, if the textfield contains a specific word, you would move to the next scene. And its not working even know I am not getting any errors
private var inTrigger = false;
var stringToEdit : String = "";
function OnTriggerEnter(other: Collider)
{
if (other.CompareTag("Player"))
{
inTrigger = true;
}
}
function OnGUI()
{
stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 23);
if (inTrigger == true)
{
if (stringToEdit == "times")
{
Application.LoadLevel("Scene2");
}
}
}
function OnTriggerExit(other: Collider)
{
if (other.CompareTag("Player")
{
inTrigger = false;
}
}
Please format your code correctly.
It's JAVASCRIPT, not Java - they're completely different languages.
"it don't work" - so what does happen? Does inTrigger get set to true when you enter the trigger as you expect? Does stringToEdit get set to the value you expect? Put some Debug.Log statements in there to see what's going on.
It wont load scene2 or give any indication that any thing about it working
I get an error that says "The referenced script on this Behaviour is missing"
I fixed the error and it still will not work its not switching to scene2
Answer by clunk47 · Nov 15, 2013 at 08:58 PM
My God man. The error is self explanatory lol:
BCE0044: expecting ), found
You're missing a closing parenthesis. ')'
Change
if (other.CompareTag("Player")
To
if (other.CompareTag("Player"))
Dude, "does not work" isn't helping us help you at all. If you "Fixed it" it would work lol XD... That's why I edited your question in the first place. If you really need help, put some effort into your question. $$anonymous$$issing reference error you stated in a comment above usually means you've deleted a script, and didn't remove it from your object first. Have a look at all the objects in your scene and the components attached in the inspector. If a component shows as "$$anonymous$$ono Behaviour", remove it. Problem solved. If this helps, don't forget to accept the answer / vote up any other comments or answers that helped.
What im trying to say is that im not getting any errors but it still will not work it will not switch to scene2
Don't put that code inside your GUI code. ONLY put GUI code in GUI Function. Place this:
if (inTrigger == true)
{
if (stringToEdit == "times")
{
Application.LoadLevel("Scene2");
}
}
Inside of Update()
Its not working would the placement of "stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 23);"
matter? its currently in the Ongui function
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error I don't know how to fix 1 Answer
BCE0005: Unknown identifier: 'spriteRenderer'. 2 Answers
Error in distance coding 1 Answer
Javascript Compile error 2 Answers