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
1
Question by jowlzz · Jul 29, 2014 at 10:10 AM · arrayjava

Changing scene when all the object is destroyed

so here, let say i have 3 gameobject(cubes) with different names, i did use Destroy(gameObject) and its fine. but my problem is, im having a trouble making script that if i clicked the gameObject / Destroyed. it will change the scene/load level. any answer would be much appreciated.

Comment
Add comment · Show 4
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 sethuraj · Jul 29, 2014 at 10:13 AM 0
Share

You meant to change the scene when all the three objects you mentioned get destroyed..?So you need to detect whether the 3 objects are destroyed or not..?

avatar image jowlzz · Jul 29, 2014 at 11:39 AM 0
Share

exactly...

avatar image RabidCabbage · Jul 29, 2014 at 01:09 PM 0
Share

@Bojidar : Post it as an answer, so I can't vote for you. :)

avatar image Bojidar · Jul 29, 2014 at 01:13 PM 0
Share

There is a little button on the left, so you can vote comments up (no button to vote down).

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bojidar · Jul 29, 2014 at 12:58 PM

Use GameObject.Find("name1") and GameObject.Find("name2") when you Destroy "name3".. If both return null, then you must load the scene/level. Same goes for the other two cubes.

Comment
Add comment · 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
0

Answer by dsada · Jul 29, 2014 at 01:14 PM

EDITED:

You can put a script on each cube that has the following in it:

 public class DestroyDetection : MonoBehaviour
     {

        private static int objectsNeedToBeDestroyed = 0; 
        private static int objectsDestroyed = 0;
        
        void Start()
        {
           ++objectsNeedToBeDestroyed;
        }
 
        void OnDestroy() //will be called on destroying the object
        {
           if(++objectsDestroyed == objectsNeedToBeDestroyed)
           {
              Application.LoadLevel("YourLevelName");
           }
        }
     }

  

Note that this hasnt got an Update function that makes this optimal

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 Bojidar · Jul 29, 2014 at 01:16 PM 0
Share

All three objects must be destroyed before you change the scene ($$anonymous$$aybe use a statc class?).

avatar image dsada · Jul 29, 2014 at 01:17 PM 0
Share

Oh i see. I edit my code right away :)

avatar image
0

Answer by Paulo33 · Jul 29, 2014 at 01:34 PM

Super Simple way...

 var objectsCollider: Collider;
 
 var objectsCount: int = 0;
 
 function Update(){
     if(objectsCount >= 3){
         application.loadlevel("Blablabla");
     }
 }
 function OnColisionEnter(objectsCollider:Collider){
     objectsCount++
 }
Comment
Add comment · 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
0

Answer by sethuraj · Jul 29, 2014 at 02:12 PM

Another simple way of doing this is to keep the three cubes as a child of an EmptyGameObject and check against if the child count is zero or not.Simple...Like this

 void Update()
 {
   //If there are no child (which are the cubes) then change the scene
   if(transform.childCount<1)
   {
      Application.LoadLevel("YourLevelName");
   }
 }
Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Input wont work!!! 0 Answers

When using input, array.Add replaces the last member 1 Answer

Adding instantiated objects to arrays 1 Answer

loading a folder of textures to an array 0 Answers

Sorting an Array of GameObjects by Name 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