I am trying to instantiate prefabs and then be able to walk around with a first person controller and destroy the ones I deem unworthy.
public GameObject RabbitObj;
void Start()
for (int i=0;i<=RabbitInit;i++)
{
Position.x=(float)(UnityEngine.Random.value-0.5)*90f+50f;
Position.y=100.5f;
Position.z=(float)(UnityEngine.Random.value-0.5)*90f+50f;
var qq=GameObject.Instantiate(RabbitObj,Position,Quaternion.identity);
qq.name=("Rabbit"+i.ToString());
RabbitObject.Add(qq);
}
I have been using the Destroy function but it does not have the desired outcome. It deletes one object but when I try delete another object it returns the following error:
“MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.”
I think I understand why it is saying that (as it has deleted the “RabbitObj” GameObject); I just dont know how to delete just one of the cloned game objects I have instantiated.
I would really appreciate any help