Search Unity

making a script wait for x seconds

Discussion in 'Scripting' started by carbondudeoxide, Mar 24, 2013.

  1. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    hello, i am currently doing some scripting with transformations and i would like my script to hang or wait for x seconds and then continue.

    this is the current script that i ahve and it works as a co routine but i would like to make it so it holds the script here while its doing it.

    Code (csharp):
    1.     private IEnumerator MoveChevron(){
    2.         for(int i = 0; i < 5; i++) {
    3.             chevron7.transform.Translate(-Vector3.up * 0.015f);
    4.             yield return new WaitForSeconds(0.01f);
    5.         }
    6.         yield return new WaitForSeconds(10);
    7.         for(int i = 0; i < ; i++) {
    8.             chevron7.transform.Translate(Vector3.up * 0.015f);
    9.             yield return new WaitForSeconds(0.01f);
    10.         }
    11.     }
    i may just be in the mind set of the old engine that i used which used Lua s its language which had a very nice wait() which did exactly want im trying to do now just without coroutines :)
     
  2. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    not really possible to halt Update, etc of a script. If you need finer controls, consider using InvokeRepeating and Invoke and yield the return of a coroutine