- Home /
Question by
DrMobile · Nov 29, 2017 at 06:44 PM ·
instantiatedestroyoverlap
How to prevent intantiate overlap prefabs
Hi everybody..I'm trying to make a simple 2d balloon game. My script intantiates random prefabs with different tags. when i try to destroy the prefabs; if there is another same prefab/prefabs that instantiated before at the scene, my destroy script destroys the other one.
I want my script to intantiate the new one when the other one is out of screen or when it destroyed.how can i prevent instantiate overlap prefabs?
public GameObject[] obj;
void Start()
{
InvokeRepeating("spawnobj", 1.0f, 2.0f);
}
void spawnobj()
{
transform.position = new Vector3(Random.Range(-12, 12), Random.Range(-7, -4), 0);
int x = Random.Range(0, obj.Length);
Instantiate(obj[x], transform.position, Quaternion.identity);
}
Comment
Your answer
Follow this Question
Related Questions
walk through an object once 0 Answers
Destroying childs and Instantiate [C#] 0 Answers
Why are my cached (in an array) gameobjects disappearing? 0 Answers
Destroy and instantiate far objects 2 Answers