Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to call a while loop?

Discussion in 'Scripting' started by smokegun, Sep 30, 2014.

  1. smokegun

    smokegun

    Joined:
    Dec 13, 2012
    Posts:
    170
    Hello i am making a game like curve Fever.
    I want that the player placeses a block every 1 second behind him.
    The problem is that i don't know how to call the while loop i made this script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Draw : MonoBehaviour {
    5.  
    6.     public GameObject prefab;
    7.    
    8.    
    9.     void Start ()
    10.     {
    11.         MyLoop2 ();
    12.     }
    13.  
    14.     IEnumerator MyLoop2 () {
    15.         while (true) {
    16.             Debug.Log ("I've washed a cup!");
    17.             yield return new WaitForSeconds (1);
    18.         }
    19.     }
    20. }
    Why doesn't this work???
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Code (csharp):
    1.  
    2. StartCoroutine(MyLoop2());
    3.  
     
    smokegun likes this.
  3. smokegun

    smokegun

    Joined:
    Dec 13, 2012
    Posts:
    170
    Thank you i am just stupid......