- Home /
Question by
DigitalWolf · May 03, 2016 at 02:17 PM ·
c#instantiatetriggerspawn
Spawn OnTriggerEnter
using UnityEngine;
using System.Collections;
public class SpawnItem : MonoBehaviour {
public Transform[] spawnpoints;
public float spawntime = 1.5f;
public GameObject[] en2;
void Start ()
{
InvokeRepeating ("SpawnEnemy" , spawntime, spawntime);
}
void SpawnEnemy ()
{
int spawnIndex = Random.Range (0,spawnpoints.Length);
int objIndex = Random.Range (0, en2.Length);
Instantiate (en2[objIndex], spawnpoints [spawnIndex].position, spawnpoints
[spawnIndex].rotation);
}
}
with this script every 1.5 seconds my empty object( to which I attached this scipt and contains other objects empty) spawn random objects that I entered in the insperctor. I don't want that an object spawn every 1.5 seconds, but spawn only when a previously spawn object enter into a trigger.
What should I change?
Comment