Instantiate

Updated 4 days ago in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 6 days ago

I want to instantiate an object in my list every x seconds but i want it to be at a specified location. more specifically, I want it to spawn 20f down on the y axis, and make it keep spawning 20 f down from the last spawn 

using UnityEngine;
public class GM : MonoBehaviour {
 public float Timer = 2;
 public GameObject[] objects;
 void Update()
 {
 Timer -= Time.deltaTime;
 if (Timer <= 0f)
 {
 int rand = Random.Range(0, objects.Length);
 Instantiate(objects[rand], transform.position, Quaternion.identity);
 Timer = 10f;
 }
 }
}
  • Liked by
Reply
1 5 days ago
using UnityEngine;
public class GM : MonoBehaviour
{
     public float Timer = 2;
     public GameObject[] objects;
     private Vector3 spawnPos = Vector3.zero;
     void Update()
     {
         Timer -= Time.deltaTime;
         if (Timer <= 0f)
         {
             int rand = Random.Range(0, objects.Length);
             Instantiate(objects[rand], spawnPos, Quaternion.identity);
             Timer = 10f;
             spawnPos.y -= 20f;
        }
    }
}

 

4 days ago

thank you so much

Show more replies
  • Liked by
Reply
Cancel