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

Question spawn rate equally in 3 spawn point how to make it random spawn rate

Discussion in 'Scripting' started by hledward7, Jun 4, 2021.

  1. hledward7

    hledward7

    Joined:
    Jul 9, 2019
    Posts:
    8
    the output of these code is spawn rate equally to 3 spawn point, how to make it spawn rate different in 3 spawn point
    Code (CSharp):
    1.   void SpawnObstacle1()
    2.     {
    3.         for (int i = 0; i < spawnPoint.Length; i++)
    4.         {   //random rate
    5.             float RandomSpawnRate = Random.Range(1f, spawnRate);
    6.             // time rate for next spawn spawnrate
    7.             nextSpawn = RandomSpawnRate + Time.time;
    8.             // ramdom obstacle in obstacles length( how many obstacle inside array)
    9.             int randomObstacle = Random.Range(0, obstacles.Length);
    10.             // object output  at the position
    11.             Instantiate(obstacles[randomObstacle], spawnPoint[i].position, Quaternion.identity);
    12.         }
    13.     }
     
    Last edited: Jun 4, 2021
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Instead of an array of Transform, use an array of an object that contains a Transform and another variable called spawnRate. for example.
     
  3. hledward7

    hledward7

    Joined:
    Jul 9, 2019
    Posts:
    8
    ok... i put the different transform speed for the spawn object