[CLOSED] How to make a loop in JavaScript

Hi Guy,

I have this script and i would like it to loop but i dont know how.

Here is the script Im using.

function Update()
{   
if (Input.GetKey(KeyCode.Space))
    Screen.lockCursor = true;
    
if (Input.GetKey(KeyCode.Escape))
    Screen.lockCursor = false;
    
}

Thanks for the help!

I think you dont need a loop, because Update function updating continuously so always run this code block with a loop.

if (Input.GetKey(KeyCode.Space)) Screen.lockCursor = !Screen.lockcursor;

This script does what I want it to do! =D

#pragma strict

function Start() 
{

//Screen.lockCursor = true;
Screen.showCursor = false;

}

function Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
        Screen.lockCursor = !Screen.lockCursor;
}