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 Bunnytoes · May 13, 2021 at 05:51 PM · spawning problems

I need my object to spawn after it dies

I have to keep spawning enemies after the main enemy dies, here is the code using System.Collections; using UnityEngine; using UnityEngine.UI; public class WaveSpawner : MonoBehaviour { public Transform enemyPrefab; public Transform SpawnPoint; public float TimeBetweenWaves = 6.5f; private float countdown = 3f; public Text waveCountdownText; private int WaveIndex = 0; void Update() { if (countdown <= 0f) { StartCoroutine(SpawnWave()); countdown = TimeBetweenWaves; } countdown -= Time.deltaTime; waveCountdownText.text = Mathf.Round(countdown).ToString(); } IEnumerator SpawnWave() { WaveIndex++; for (int i = 0; i < WaveIndex; i++) { SpawnEnemy(); yield return new WaitForSeconds(0.7f); } } void SpawnEnemy() { Instantiate(enemyPrefab, SpawnPoint.position, SpawnPoint.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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ytsorf · May 13, 2021 at 07:27 PM

Hi there try to use this:

 `
 void SpawnEnemy() { 
 GameObject enemy = Instantiate(enemyPrefab, SpawnPoint.position, SpawnPoint.rotation);
  }
 `

in this way you can destroy and spawn any enemies you want, hope it help <3

@Bunnytoes

Comment
Add comment · Show 5 · 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 HammockHead21 · May 14, 2021 at 03:20 AM 0
Share

Fyi, if you are going to spawn lots of enemies it's probably better to create a pool of them and then disable the game object instead of deleting it.

avatar image Bunnytoes HammockHead21 · May 14, 2021 at 12:17 PM 0
Share

I need them to spawn in waves etc 1 enemy 1 enemy 2 enemy 3 enemy etc

avatar image Bunnytoes · May 15, 2021 at 12:30 AM 0
Share

hey @Ytsorf where should I add this, also can you edit and leave the full code down below, thanks. the code doesn't work

avatar image Ytsorf Bunnytoes · May 15, 2021 at 01:04 AM 1
Share

well, if you want to create a system of Waves and enemies thats gonna be a lil tricky thing to do but its simple, you make a List where you gonna store the prefabs, a bool that will check if all enemies are kill/destroy,an int that will store the value of the wave(UI), a void to spawn enemies and a IEnumerator that will use all that to check if the enemies are kill and spawn the next wave with foreach.

avatar image Bunnytoes · May 15, 2021 at 02:34 PM 0
Share

thanks @Ytsorf, please leave the done down below that would help me so much, thanks -Bunnytoes

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

119 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

Related Questions

Objects spawning in each other 1 Answer

im having problems spawning these prefabs in a grid next to each other with some spacing thanks in advance 0 Answers

Object Pooling Spawn,Unity slows down when object pooling,Unity Slows down when Object Pooling 1 Answer

How to spawn all humans at once and activate then with time? 1 Answer

Why doesn't my spawning code work? 2 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