Search code examples
c#unity-game-enginerestart

Restart game after after 2 minutes of inactivity


I'm trying to figure out how to begin writing a piece of code that listens for user activity. If there is absolutely no activity after a few minutes I want the game to restart. Can someone recommend a good starting point to get something like this working?


Solution

  • If you are wondering how to capture all input from everywhere, take a look at

    Input.anyKeyDown
    

    http://docs.unity3d.com/ScriptReference/Input-anyKeyDown.html

    In addition you can also check that the mouse position is still the same as the previous frame. Use this in combination with @Neeraj Kumar's answer i.e.

    private Vector3 prevMousePosition = Vector3.zero;
    void Update()
    {
        if(Input.anyKeyDown || Input.mousePosition != prevMousePosition)
             RestartGameInvoke();
    
         prevMousePosition = Input.mousePosition;
    }