Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 hlikulumbi · Feb 25, 2020 at 05:09 AM · timerscene-loadingdestroy objectdestroygameobjecttrial

Trying to change scenes after objects are destroyed

I'm making a time trial like game, where you have to destroy targets as fast as possible. Your time is recored and displayed in the next scene. I have been able to apply this to each target; however, when one target is destroyed it'll immeduiately change scenes without the others being destroyed.

using UnityEngine.UI; using UnityEngine; using UnityEngine.SceneManagement; using System.Collections;

public class Target : MonoBehaviour { public float health = 1f; public float score = 0f; public void TakeDamage (float amount) { health -= amount; if (health <= 0f) { Die(); score++; } }

 void Die()
 {
     Destroy(gameObject);
 }
 private void OnDestroy()
 {
     SceneManager.LoadScene("FinalTime");
 }

}

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 Batuhan13 · Feb 25, 2020 at 06:17 AM

Good morning mate =) .I found a simple way to do that .First of all I created a array gameobject named as enemies than I equaled it to GameObject.FindGameObjectWithTag("Enemy"); .After that I created a new for function which checks every enemy if for function founds every enemy dead it will enable bool value. Here the code =)

 public class Logic : MonoBehaviour
 {
     public bool isAllEnemiesDied;
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         GameObject[] enemies= GameObject.FindGameObjectsWithTag("Enemy");
 
         if (enemies.Length == 0&&isAllEnemiesDied==true) 
         {
             Debug.Log("You killed all enemies wp=)");
         }
  
         for(int i = 0; i < enemies.Length; i++) 
         {
             if (enemies[i] != null&&isAllEnemiesDied==false) 
             {
                 isAllEnemiesDied = false;
                // Debug.Log("There are a " + enemies.Length + " enemy alive =(");
             }
         }
 
     }
 }

When I writing here I notice that we can make this more shorter =). In update function these two lines will be do same think I guess =)

 GameObject[] enemies= GameObject.FindGameObjectsWithTag("Enemy");
  
          if (enemies.Length == 0&&isAllEnemiesDied==true) 
          {
              Debug.Log("You killed all enemies wp=)");
          }

Comment
Add comment · Show 1 · 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 hlikulumbi · Feb 25, 2020 at 06:14 PM 0
Share

Didn't exactly work for me, I was told that I could tell the system that when all objects tagged with target are no longer in the heirarchy I could load the next scene

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

125 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

Related Questions

how to destroy all gameobjects with a certain tag? 1 Answer

Unity createNew Game Object after calling a Destroy() 1 Answer

How do I Destroy a Child after Instantiating it? 1 Answer

Need some help an object collider that stops a timer then displays it on another scene 1 Answer

MissingReferenceException after loading a scene, missing object of type text and button. 0 Answers


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