- Home /
Question by
unity_VUGXPfWcVjpCww · Aug 23, 2021 at 09:38 PM ·
objectdestroyorder
how to predefine an order to destroy objects
the game I am designing is a mix between a runner and a puzzle game. The goal is simple you have to hit the cubes of the player in order to get the same shape as the square in the arch. I would like to know how to destroy in an exact order of objects here is an example.
And here is the code in which I manage my collisions.
public class Collision : MonoBehaviour {
public GameObject destroyedParticle;
public int maxHealth;
public int currentHealth;
Material m_Material;
void Start()
{
m_Material = GetComponent<Renderer>().material;
currentHealth = maxHealth;
}
void OnMouseDown() //If the object has been clicked
{
if ((FindObjectOfType<Player>().ammoCount > 0) && (!FindObjectOfType<Player>().gameIsOver)) //If the player has ammo and the game is not over yet
{
currentHealth -= 1;
FindObjectOfType<Player>().ammoCount -= 1; //Reduces ammo
m_Material.color = Color.grey;
if (currentHealth <= 0)
{
FindObjectOfType<AudioManager>().HavocSound(); //Sound effect plays
Destroy(Instantiate(destroyedParticle, transform.position, Quaternion.identity), 1f); //Instantiates a particle and destroys it after x seconds
Destroy(gameObject); //Destroys the cube which has been clicked
//FindObjectOfType<Player>().ammoCount--; //Reduces ammo
}
}
}
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Obstacle")) //If gameobject collides with an obstacle, then game is over
{
//Game over functions
FindObjectOfType<AudioManager>().DeathSound();
Destroy(Instantiate(destroyedParticle, transform.position, Quaternion.identity), 1f);
GetComponent<Animation>().Play("CubeDeathAnim");
FindObjectOfType<Player>().gameIsOver = true;
FindObjectOfType<GameManager>().EndPanelActivation();
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Animation>().Play("CameraDeathAnim");
}
}
}
I would like to make a well-defined order to destroy the objects. For example first destroy the cube1 and after the cube2.
a.png
(14.3 kB)
Comment
Your answer
Follow this Question
Related Questions
How to set Object destruction order at game over 0 Answers
How to remove an object from an array once it has been destroyed 1 Answer
Pick up objects 2 Answers
How to destroy a unit contained in multiple lists 1 Answer
Can't destroy a script. 1 Answer