PowenKo, Unity Tutorial 149-1,Timer, yield WaitForSeconds

October 30, 2011   ·   0 Comments

function UnlockLevelExit()
{

yield WaitForSeconds(1);
	exitGateway.active = false; // ... the fence goes down briefly...
	yield WaitForSeconds(0.2); //... pause for a fraction of a second...
	exitGateway.active = true; //... now the fence flashes back on again...

}

reference: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.StartCoroutine.html

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void Start() {
        print("Starting " + Time.time);
        StartCoroutine(WaitAndPrint(2.0F));
        print("Before WaitAndPrint Finishes " + Time.time);
    }
    IEnumerator WaitAndPrint(float waitTime) {
        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint " + Time.time);
    }
}
using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    IEnumerator Start() {
        print("Starting " + Time.time);
        yield return StartCoroutine(WaitAndPrint(2.0F));
        print("Done " + Time.time);
    }
    IEnumerator WaitAndPrint(float waitTime) {
        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint " + Time.time);
    }
}
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon