Script activate after amount of time

I have been working on a project where I faint after a certain amount of time. I used the space bar to activate the faint but I am having trouble finding anything that i can understand. Can someone show me a link or a pointer on how to do this. (i am a beginner to unity and scripting). Thank you.

make something happen in the future, coroutines and invoke header

mark as answered and have a nice day.

Look into how “coroutines” are used.

You can use “yield” statements to delay the execution of code.

As an example, you could start with something like:

void Update()


if (Input.GetKeyDown("space"))





IEnumerator Faint()


print("Disable something here");

yield return new WaitForSeconds(5);

print("Enable something here");


You can use the following code to delay something:


var delay:float;

function Faint(){
var timePointer:float=Time.time+delay;

/fainting code here.