Keep mouse state on changing level

Hi!

I need to keep the state of mouse on changing level.

I explain with a pseudo-code:

        void Start()
        {
            if (Input.GetMouseButton(0))
            {
                isDown = true;
            }
            //isDown is always false :(
        }

        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Application.LoadLevel(Application.loadedLevelName);
            }
        }

After loading, I need to check if the mouse if down or not, but it seems the internal mouse state is reset when I call Application.LoadLevel. Even

        Input.GetMouseButtonUp(0);

return always false until I release the mouse button, then I push on the mouse button and I release it again.

Any idea?

Thanks.

Not sure what are You trying to do. But I will try to guide You :slight_smile:

If You want to keep the state of the isDown between levels than You can add this to your script.
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
This will make the object(and script) stay even after loading another scene/level.
Otherwise the object(with script and state of the isDown) will be destroyed when loading new scene.

Also You can try to use Input.GetMouseButtonUp or Input.GetMouseButtonDown It will return true when user releases or presses the button mouse :slight_smile:

Hope this will help You :slight_smile: