this is in my pause menu to lock the cursor to the center but when i press escape free it for a bit to press option buttons then when i press escape again to lock it to the center again,what arent i doing?
var SwitchOnSound:AudioClip;
var SwitchOffSound:AudioClip;
private var Off : boolean = false;
private var On : boolean = true;
function Start () {
Screen.lockCursor = true;
}
function Update()
{
if(Screen.lockCursor)
{
if(Off)
{
if(Input.GetKeyDown(KeyCode.Escape))
{
On = true;
Off = false;
AudioSource.PlayClipAtPoint(SwitchOnSound, transform.position);
}
}
else
{
if(On)
{
if(Input.GetKeyDown(KeyCode.Escape))
{
On = false;
Off = true;
AudioSource.PlayClipAtPoint(SwitchOffSound, transform.position);
}
}
}
}
}