User:Shannon

Author: Shannon

Description
This script will hide the pointer after two minutes if the mouse does not move for a designated period of time. It is also an example of how to use enum and switch define a state machine.

Usage
To use this script, attach it to any game object in your scene.

CSharp - PointerManager.cs
// PointerManager.cs // Shannon Ware (cc) 2008 All Rights Reserved // July 30, 2008

using UnityEngine; using System.Collections;

public class PointerManager : MonoBehaviour { // STATIC PARAMETERS public static enum PointerState { stateInvisible, stateVisible, stateSetInvisible, stateSetVisible }	// PUBLIC VARIABLES public string version = "1.0.0";	// "[ReleaseID].[BetaID].[BuildID]" // PRIVATE VARIABLES public bool debug = false; public bool console = false; public bool hideOverride = false; public PointerState pointerState = PointerState.stateSetInvisible; public float timeOutReset = 2f; public float timeOutCounter; public Vector3 currentMousePosition; // CLASS METHODS // EVENT HANDLERS void Start { currentMousePosition = Input.mousePosition; }	void Update { switch (pointerState) { case PointerState.stateInvisible: if (!hideOverride) if (Input.mousePosition != currentMousePosition) pointerState = PointerState.stateSetVisible; break; case PointerState.stateVisible: if (timeOutCounter > 0f) timeOutCounter -= Time.deltaTime; else pointerState = PointerState.stateSetInvisible; break; case PointerState.stateSetInvisible: if (console) DebugConsole.Log("PointerManager:Update; State set visible at "+Time.time.ToString("f2")); if (debug) Debug.Log("PointerManager:Update; State set visible at "+Time.time.ToString("f2")); Screen.showCursor = false; currentMousePosition = Input.mousePosition; pointerState = PointerState.stateInvisible; break; case PointerState.stateSetVisible: timeOutCounter = timeOutReset; Screen.showCursor = true; pointerState = PointerState.stateVisible; break;

}	} }