Instantiate an object when you collide with that object

Hey! I’m trying to instantiate an object when I collide with it and it works, the problem is that I want that object to disappear and then that same object appear in another place, I have used destroy but the thing is that once I try to grab it for the second time it throws a null reference exception because the object cant be accessed anymore since it’s destroyed. I also tried setting renderer and collider to false but it is the same issue… any answers??, Thanks a lot in advance!!!

if(other.gameObject.tag=="bad")
	{
		cylinder.transform.localScale+= new Vector3(-1,0,-1);

	}

	else if(other.gameObject.tag=="good")
	{
		cylinder.transform.localScale+= new Vector3(1,0,1);
		Instantiate (cube,new Vector3(Random.Range(-30.0F, 30.0F), 0, Random.Range(-30.0F, 30.0F)),transform.rotation);
	
		Instantiate(good,new Vector3(Random.Range(-5.0F, 5.0F), 0, Random.Range(-5.0F, 5.0F)),transform.rotation);
		Destroy (other.gameObject);

1 Answer

1

Why not just move the object to a random location when you hit it?

Hahaha! thanks!, it was so obvious!