My script isn't working

For some odd reason, my scripts cant run. I’ve done simple things like Debug.Log(“Hai”);
BTW: I’m using JS
My current script is:

function Update() {
    if(Input.GetMouseButtonDown(0))
        Debug.Log("Pressed left click.");
    if(Input.GetMouseButtonDown(1))
        Debug.Log("Pressed right click.");
    if(Input.GetMouseButtonDown(2))
        Debug.Log("Pressed middle click.");
}

Please Help

Is your script attached to a gameobject in the scene?

1 Like

No, but I tried to connect it to a cube, didn’t work

Just tried the exact code you have on a cube and it works… Are you sure you’re testing the clicks on the “Game” window in unity and not in the sceneview?

Im sure its on the game screen, because it goes fullscreen. What im really trying to do is make a script that waits like 1 second and goes to a different level. But of course it didnt work, so i tried that simple script.

And there is no output in the console window with the debug.logs?

For changing scenes, Look into
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
https://docs.unity3d.com/Manual/Coroutines.html (can use coroutines to wait for a select amount of time) or using https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html which can provide the same functionaility.

Ok, I somehow got it to work :smile:. I looked at some of the links and it copied a line in there, and it magically worked. Thank You!

You’re just starting out. I would sincerely suggest that you consider switching to C# for your programming in Unity. UnityScript (javascript, as you called it) is being phased out. Besides that, even while it’s here, there is a lot more help on the forums for C#, and elsewhere online. =)

Have fun :slight_smile:

+1 for switching to c#. Unity has already announced it will be dropping support for Unityscript.