i am using this script to destroy my object, activating after the event key in animation.
public void CallDestruction(){
Destroy(this.gameObject);
}
Obviously after my object is destroyed it doesn’t come back, but I need it every time I destroy my object,It appears again in a random “y” position forever.
BMM7
September 27, 2019, 1:54am
2
You destroy your object and then you want to create it again on the scene, right?
Create an empty object on Hierachy, and in code attached to this empty object, instantiate the destroyed object again:
public Vector3[] positions;
public GameObject objectPrefab;
void Start() {
SpawnNext();
}
void SpawnNext () {
var randomIndex = Random.Range(0, positions.Length);
Instantiate (objectPrefab, positions[randomIndex], Quaternion.identity);
}
BMM7:
You destroy your object and then you want to create it again on the scene, right?
Create an empty object on Hierachy, and in code attached to this empty object, instantiate the destroyed object again:
public Vector3[] positions;
public GameObject objectPrefab;
void Start() {
SpawnNext();
}
void SpawnNext () {
var randomIndex = Random.Range(0, positions.Length);
Instantiate (objectPrefab, positions[randomIndex], Quaternion.identity);
}
I LOVE YOU. Thank you very much