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; 
    }
}

What error is it failing with?

1.) Please format your code correctly. 2.) It's JAVASCRIPT, not Java - they're completely different languages. 3.) "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

1 Answer

1

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"))

Thanks but I fixed it and it still dose not work

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

Immediately before the line if(stringToEdit == "times"), put Debug.Log("stringToEdit is: " + stringToEdit);. What value does it report in the console?