Wait Command?

I have this script in Java
if(breaker>2)
{
// At skyde
if(Input.GetButtonDown(“Jump”))
{
var bullit = Instantiate(bullitPrefab, GameObject.Find(“Spawn”).transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 400);

breaker-=1;

}

After Breaker -=1 i want the script to wait for like 2 secounds before it complete it?
How do I do that?

Use coroutines. Unity - Scripting API: MonoBehaviour.StartCoroutine

This would do:

void Update() {
if(breaker>2)
{
// At skyde
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab, GameObject.Find("Spawn").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 400);

breaker-=1;
StartCoroutine(WaitAndComplete(2.0)); 

}
}

function WaitAndComplete (waitTime : float) {
// suspend execution for waitTime seconds
yield WaitForSeconds (waitTime);
print ("Completed!");
//complete code here
}

you can put “yeild waitForSecond();”

I got this fail

myScriptName.js(48,30): UCE0001: ‘;’ expected. Insert a semicolon at the end

Line number |
46 if(breaker<=2)

47 {

48 yeild waitForSecond(2);

49 breaker+=5;

50 }

I can see that line 48 has a semicolon?

And two typos. Always look at all the errors, not just the last one.

–Eric

There is only this error

The code you linked contains two errros. yield is spell incorrectly and WatForSeconds is not the correct capitalization. However you might of just hand typed the code as your error post.

yield waitForSeconds(2);

Thanks :wink: