Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by unity_VUGXPfWcVjpCww · Aug 20, 2021 at 03:57 PM · objectdestroy objectorder

how to predefine an order to destroy objects on Unity?

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. alt text

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)
a.png (14.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating an array of objects in the order they are in a folder? 0 Answers

Objects getting destroyed in unity test, but only sometimes in the phone app 0 Answers

Can you get a value from a object when destroyed? 2 Answers

Colliders have a different postion to wheels want to reset colliders to have new postion origin 0 Answers

Code still trying to access Object that has been destroyed. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges