- Home /
 
how to freeze a random position?
hello. i know how to create a random position, but i don't know how to freeze my spawn point, to that random position, while it Instantiate's some enemies to play with. here's my script:
 private var randStop = 0; private var enemy_Spawned = 0; var enemy_Prefab : GameObject; private var numberOfWaves = 0;
 
               //Variable to do with enemy fuction var point1: Transform; private var point1_Check : boolean = false;
 
                function enemy() { //three different spawn points on spawning area
 
                 if(!point1_Check) 
  {
      Instantiate(enemy_Prefab, transform.position, Quaternion.identity);
      enemy_Spawned ++;
      point1_Check = true;
  }
 
                }
 
               function Update () {
 
                //setup for spawn point random position, and stop. if(randStop == 0) { transform.position.x = Random.Range(-55, 48); randStop = 1; }
 
                //load enemy fucntion, when spawnpoint has stoped if (randStop == 1) { enemy(); }
 
                //when there are three spawned enemies, random the spawnpoint again if(enemy_Spawned == 1) { randStop = 0; numberOfWaves ++; }
 
                if (numberOfWaves == 3) { randStop = 3; }
  
                } 
if it's too complicated to read, i'm basically, setting a rand_Stop varible, and using if statement's when the variable is at a particular value. so when it's at 0, it generate a new radom spawnpoint, and sets it to 1, when set to 1, 1 enemy_Prefab will be instantiated. then i set another varible to something simular, when there are X amount of enemies spawned, turned rand_Stop to 0 again and add 1 to NumberOfWaves, where, finally, at the 3 number of waves, rand_Stop will be set to 3, where the loop will be broken.
the only problem is, is that all it does, is create one enemy, and kepp setting a random position for my spawnpoint. what do i do?
The code is a little convoluted, but as for why only one enemy is being spawned, it looks like it's because an enemy is only spawned when 'point1_Check' is false, but in the block of code that spawns the enemy, you set 'point1_Check' to true (meaning that no more enemies will be spawned).
Answer by Nathan Bennett · Sep 12, 2010 at 06:46 AM
i have redone this script 5 times now, to make it as easy as i could. what i need is a Random.Seed number, which i don't know how to set, and don't know what to set it to. (i'm trying System.DateTime.Now.Ticks)
looks like more G.O.o.g.l.e for me
Your answer