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 /
  • Help Room /
avatar image
0
Question by Caldera12 · Apr 04, 2018 at 09:34 AM · enemyspawner

Change level once killed enemy

Hi guys I want to make it so the scene can change to another scene once i killed the last enemy. Here's my enemy spawner script

 public GameObject enemy;

 public Transform[] spawnPoints;

 public Vector3 spawnValues;
 public int howoften = 10;
 public int howmany = 3;
 public float etimer;

 void Update()
 {
     etimer = etimer - Time.deltaTime;
     if (etimer < 0)
     {
         etimer = howoften;

         int i = howmany;
         while (i > 0)
         {
             i--;

             int spawnPointIndex = Random.Range(0, spawnPoints.Length);
             Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);


         }
         
     }

 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Koyemsi · Apr 04, 2018 at 09:54 AM

Maybe like this :

 while (i > -1) 
 {
     i--;
     if (i > 0) {
         int spawnPointIndex = Random.Range (0, spawnPoints.Length);
         Instantiate (enemy, spawnPoints [spawnPointIndex].position, spawnPoints [spawnPointIndex].rotation);
     } else {
         SceneManager.LoadScene ("myScene");
     }
 }
Comment
Add comment · Show 13 · 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 Caldera12 · Apr 04, 2018 at 10:19 AM 0
Share

it dose change scenes but it changes as soon as the game starts

avatar image Koyemsi Caldera12 · Apr 04, 2018 at 10:29 AM 0
Share

Oops, sorry ! That's strange, as i should be > 0.

avatar image Caldera12 Koyemsi · Apr 04, 2018 at 10:32 AM 0
Share

where should that be at the start?

Show more comments
Show more comments
avatar image
0

Answer by Gordrik · Apr 04, 2018 at 09:50 AM

 private int sceneID;
 private GameObject[] enemyCount;
 
  void Start()
     {
         enemyCount = GameObject.FindGameObjectsWithTag("Enemy");
         sceneID = SceneManager.GetActiveScene().buildIndex;
     }
     private void Update()
     {
         if (enemyCount.Lenght <= 0)
         {
             LoadOnLastKilled(SceneName);
         }
     }
     public void LoadOnLastKilled(string name)
     {
         {
             SceneManager.LoadScene(name);
         }
     }
 
 or to automatically load next level use :  
 
 public void LoadNextScene()
 {
     SceneManager.LoadScene(sceneID+1);
 }

To really make it work, you need to reduce enemyCount in Update() method every time the enemy object is destroyed, if you have any troubles with implementation, let me know.

Comment
Add comment · Show 9 · 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 Caldera12 · Apr 04, 2018 at 10:38 AM 0
Share

i get an error on LoadOnLast$$anonymous$$illed when i put it on update

if (enemyCount.Length <= 0) { LoadOnLast$$anonymous$$illed(); }

avatar image Gordrik Caldera12 · Apr 04, 2018 at 10:40 AM 0
Share

What the error says?

avatar image Caldera12 Gordrik · Apr 04, 2018 at 10:40 AM 0
Share

Assets/Scripts/Level/Spawner.cs(47,13): error CS1501: No overload for method LoadOnLast$$anonymous$$illed' takes 0' arguments

Show more comments
avatar image
0

Answer by tormentoarmagedoom · Apr 04, 2018 at 09:53 AM

Goodday.

First, use

 etimer -= Time.deltaTime

Its the same of what you use.

Second, i recommend you to create a new tag called enemy, and assignt this tag to all enemies via inspector. Then just need to.

GameObject[] enemylist = GameObject.FindObjectswithtag("enemy) if (enemylist.lenght == 0) { sceneManager.LoadScene("scenename")}

Look that the command is gameobjecS with "s". Also care with my typing, im writing from mobile so some comands have CAPS leters.

Bye!

 Accept the answer if helped!
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

79 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

Related Questions

NullReferenceExeption 0 Answers

Enemy Spawn waves, not stop keep looping 0 Answers

wave spawner difficulty increase 1 Answer

make enemy cars spawn faster over time! 2 Answers

Linking projectiles to enemy 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