I have lots of prefabs gameObjects and I Instantiate them in a parent gameObject. When the user clicks one object, the prefab destroy. I have 48 of this prefabs in the scene. But when I click one object, the other ones keep moving back and forth, like changing layers or something. One or two seem to disappear but that object just move behind others.
Here is some of the code that I’m using:
this is how I instantiate the prefabs in my gameObject parent:
public GameObject[] prefabs;
private GameObject temporalPrefabs;
int index = Random.Range(0, 20);
temporalPrefabs= Instantiate(prefabs[index], transform.position, transform.rotation) as GameObject;
temporalPrefabs.transform.parent = transform;
and this is how I destroy the clicked object (this code is added as component in each prefab)
void OnMouseDown()
{
Destroy(gameObject);
}
if some one please know what could be happening and how can I fix this I’ll be really thankful.