Time Delay for a process

I have to give the delay for the process to happen, which I am calling in the Update function. I have tried using yield WaitForSeconds(2);. But it is giving me an error: “Update() cannot be a co-routine.” Where should it be used?

Update is a function that doesn’t support coroutines. You might want to look into the CoUpdate workaround.

If you just want something to happen x seconds from now, you can also use Invoke. This example would invoke “Shoot” 2 seconds after tapping space. It can’t be invoked again until after the invoke occur 2 seconds later because of the IsInvoking test.

function Update() {
    if (Input.GetKeyDown(KeyCode.Space) && !IsInvoking("Shoot"))
        Invoke("Shoot", 2);

function Shoot() {