Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by ELBANDID0 · Feb 19, 2013 at 06:10 PM · gameobjectonmousedowndeleteorder

Easy question, deleting objects in order.

Hi

I have a bunch of spheres which get deleted OnMouseDown and on the final one you progress to the next part of the level, problem is you can just press the last one first and skip the entire thing. How do I add a prerequisite to the spheres so they can not be deleted until the ones prior to them have been already.

Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Feb 19, 2013 at 06:23 PM

Not really an easy question. There are several approaches you can take. One is to use a static variable and compare an id to the current count of remain objects. Here is the logic in C#:

 public class DeleteInOrder : MonoBehaviour {
     
     static int iCount = 5;
     public int iID = 1;
 
     void OnMouseDown()
     {
         if (iID == iCount)
         {
             if (iID == 1)
             {
                 // Next scene code
             }
             Destroy (gameObject);
             iCount--;
         }
     }
 }

The iID needs to be 1 based, so in this case there are 5 objects with id values 1 - 5. The last one to delete will have the value 1. Note that iCount and iID can be set in code if you are dynamically creating the objects.

Comment
Add comment · Show 2 · Share
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
avatar image ELBANDID0 · Feb 19, 2013 at 09:40 PM 0
Share

Ah ok, I thought it was going to be more of an 'if (other..blah)' easy answer. I write in Javascript so do you know of any decent way I can convert this? Thanks for your help robertbu.

avatar image robertbu · Feb 19, 2013 at 09:56 PM 0
Share

For most scripts that come across this list, 90% of the conversion is changing how the variables are declared. Here is the same script in unity script:

 static private var iCount : int = 5;
 public var iID : int = 1;
 
 function On$$anonymous$$ouseDown()
 {
    if (iID == iCount)
    {
      if (iID == 1)
      {
       // Next scene code
      }
      Destroy (gameObject);
      iCount--;
    }
 }

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

9 People are following this question.

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

Related Questions

OnDestroy() callback in Editor upon deleting selected GameObject - del key 5 Answers

Sorting an Array of GameObjects by Name 1 Answer

Change Mesh/Gameobject onmousedown?,Swap mesh/gameobject randomly onmousedown 0 Answers

I cant delete multiple instantiated prefabs 0 Answers

[SOLVE] 2D Space shooter - explosion power-up scripting, please help! 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