MouseButtonDown not being stored between scenes

Hi, In my game when a player presses the right mouse button in scene 0, I want scene 1 to load. (and the mouse button is kept down).
When the mouse button is released in scene 1, I want scene 0 to load again.

The first switch is easy enough - but I just can’t get the switch back working.

It seems that unity doesn’t store which key has been pressed between scenes, so when I use

 if (Input.GetMouseButtonUp(1))

in scene 1 to load scene 0 again nothing happens.

I tried attaching a script to a gameobject which isn’t destroyed between scenes and wrote this

 function Update () {
 
     if (Input.GetMouseButtonDown(1))
     {
Debug.Log ("mousedown");
      
       
     }
     
       if (Input.GetMouseButtonUp(1))
     {
Debug.Log ("mouseup");
      
          
     }
 }

To see if anything would show on the console - but it isn’t recognising that the mouse button is released.

Does anyone know how I would go about doing this?

Would it be possible to simulate the right mouse button down at the start of scene 1 in code so when it is released this is recognised - or is what I’m trying to do really not possible?

Best, Laurien

I guess that the internal state of mouse button in Unity is reset on scene load, so it does not matter in which state the mouse button is when the new scene is loaded.

After some research I’ve concluded that unity’s Input class ignores input that begun before the start of the scene. See:

I would suggest looking into different ways to achieve what you want. zaikman raises a valid point in his post on the reddit question above: ‘Do you really need an individual scene for every room/gameview you have?’

In this particular case you could - for example - have the content of both your scene 0 and scene 1 in one combined scene, at different world positions and move the camera between these positions according to the user’s mouse input. Another option would be to activated and deactivate the objects you want to display/hide.

You should try some things and use the one you feel most comfortable with.


If you still want to keep things in different scenes: other users have managed to work around the issue by using LoadLevelAdditive(), might be worth investigating that.