Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Random Planet Generator

Discussion in 'Scripting' started by medsouz, Jun 11, 2010.

  1. medsouz

    medsouz

    Joined:
    Jun 2, 2010
    Posts:
    259
    The WaitForSeconds() is having absolutly no effect and it is creating alot more than the amount from the random number...

    Code (csharp):
    1. var MinPlanets = 10;
    2. var MaxPlanets = 100;
    3. var PlanetTemp : GameObject;
    4. function Start () {
    5. var GenAmnt = Random.Range(MinPlanets,MaxPlanets);//Returns the number chosen to make a random game!
    6. while (GenAmnt > 0) {//Gen Planets here
    7. Debug.Log(GenAmnt);
    8. var NewPlanet = Instantiate(PlanetTemp,Vector3(10,GenAmnt,10),Quaternion(0,0,0,0));
    9. yield WaitForSeconds(500)
    10. GenAmnt = (GenAmnt - 1);
    11. }
    12. }
     
  2. ecnalyr

    ecnalyr

    Joined:
    May 23, 2010
    Posts:
    38
    semicolon after waitforseconds ?
     
  3. medsouz

    medsouz

    Joined:
    Jun 2, 2010
    Posts:
    259
    Its weird, when I did that there was no wait but the script didn't crash Unity anymore. :D
     
  4. ecnalyr

    ecnalyr

    Joined:
    May 23, 2010
    Posts:
    38
    So it's still not working?
     
  5. refardeon

    refardeon

    Joined:
    Feb 19, 2010
    Posts:
    49
    I don't think you can use yield inside Start() - from the manual:
    Since Start() is only called once, the yield statement won't work. So you'd have to put the generation stuff in a seperate function.
     
unityunity