need help with code

Updated on January 4, 2019 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on January 4, 2019

I need to instantiate 2 objects with the same ‘rand’ number twice in a row with set time gap, but I can’t figure out how. i have tried multiple ways, but all of them lead to objects being instantiaded very fast or not instatiating at all.
 
<
 
public class spawner : MonoBehaviour {    public GameObject [] obstacle;    private float timeBtwSpawn;    public float spawnRate;    public int repeat;    private int rand;    private void Update()    {        rand = Random.Range(0, obstacle.Length);        if (timeBtwSpawn
 
it’s c#
 
Please help me out!

  • Liked by
Reply
0 on January 4, 2019

If you want to Instantiate twice, you need to call it twice, you’re only calling it once. You also don’t need to set rand twice, especially if you want both new objects to be of the same prefab.

  • Liked by
Reply
Cancel