- Home /
Code for destroying object with particle and move to the next object.
Sample code and tutorial about destroying the object with the animation of particle system and upon the destroying object, will move to the next object..
here is the scenario of the game: The game is all about an analogy quiz which has a 5 choices. (this choices is on prefab), the user must break the 3d rocks in order to proceed into a next question to be answer, the user can only answer 1 click of the choices per question. if the user had a wrong 1 click of answer, the 3d rock will be remain in whole and faded then the final result of the score will be display..
thank you for your consideration. have a great day! :)
Answer by Etamiin · Feb 15, 2017 at 04:35 PM
U just need to instantiate the next object, and so destroy the last, maybe :
class Changer : MonoBehaviour {
public List<GameObject> Objects = new List<GameObject>();
public Transform SpawnPointObject;
GameObject actualObject;
void Start () {
ChangeObject();
}
void Update() {
}
public void ChangeObject() {
if (actualObject != null) {
Destroy(actualObect);
}
if (Objects.Count > 0) {
GameObject newObject = (GameObject)Instantiate(Objects[0]);
newObject.transform.position = SpawnPointObject.position;
Objects.Remove(Objects[0]);
actualObject = newObject;
}
else { Debug.Log("NoObjects in list"); }
}
}
U need to set all your objects in the List(in inspector), set the spawnpoint(create an ampty gameobject for the position) and call the "ChangeObjects" void for change your object.
I don't try the code, so i don't know if some error happens.
Your answer
Follow this Question
Related Questions
Script doesn't work anymore! 2 Answers
Changing ParticleSystem attributes at runtime 1 Answer
Why doesn't changing the particle's mateiral color during runtime work? 0 Answers
How do I Destroy a Child after Instantiating it? 1 Answer
Referencing Objects and disabling Scripts on them instantly 1 Answer