hello all, the problem is I have create some prefab gameobject and place them on different position, and I use OnTriggerEnter destroy them and spawn them, however I keep destroy and spawn again again and again, the gameobject starting out of my area, so how can I spawn them in random position within an area, can somebody help me with this case, thank a lot!
Sorry for my poor english, hope you guys understand.
here is my script:
public GameObject cube;
void SpawnCube(){
Vector3 position = new Vector3(Random.Range(-10.0F, 10.0F), 1, Random.Range(-10.0F, 10.0F));
Instantiate (cube, position, Quaternion.identity);
}
void OnTriggerEnter(Collider collider){
if (collider.gameObject.name == "player") {
Destroy (this.gameObject);
SpawnCube();
}
}