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 /
  • Help Room /
avatar image
0
Question by Black Widow 1 · Nov 29, 2010 at 02:10 AM · enemytimedelayrespawn

Time delay enemy respawn

What is the best way to have an enemy respawn after death and after a time delay?

I have tried yield WaitForSeconds (?) and then use the new location to respawn but it respawns instantly. I have use the renderer false but enemy is invisible and still attackes. I can instantiate the enemey prefab but the waypoints and target are missing. I'm new at this but to date have got great assistance from reading forums but now time to get into it.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by EION Technology · May 12, 2013 at 12:18 AM

With Unity, the most simple script, the better. Miguel and Uriel have good answers, but the most effective way of spawning an enemy Prefab is by having a Spawn Controller. Ill give you an example in Unity Script (you will need 2 scripts: 1.) SpawnController.js (On a new GameObject) 2.) DeathSignal.js (On enemy GameObject)

 //Spawn Controller
 
 var enemy1 : GameObject; //enemy prefab gameobject
 
 var deathTimer = 0; //time since enemy has died.
 var spawnDelay = 5; //spawn delay.
 
 static var isDead = "false";
 
 
 function Update (){
     
    if (isDead == "true"){
         deathTimer += 1 * Time.deltaTime; //start death timer.
 }
    
    if (isDead == "true" && deathTimer == spawnDelay ){
         Spawn(); 
 
 }
 }
 
 function Spawn (){
     Instantiate(enemy1, 0,0,0);
     deathTimer = 0; //reset death timer after spawning.
 }

DeathSignal.js :

      // enemyHealth can be attached to the regular health script
     // by adding enemyHealth = scriptName.Health; in Update function.
     
     var enemy : GameObject;
         
     static var enemyHealth = 100; 
    
             
             function Update(){
                  if (enemyHealth <= 0){  //when enemy health is zero or below Signal Death to Spawn Controller
                      SignalDeath();
             }
             
             }
         
         function SignalDeath (){
             SpawnController.isDead = "true";
             Destroy(enemy);
         }
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 MiguelDeLaCruz · May 05, 2011 at 08:49 PM

You could write a small manager script that will spawn this prefab and handle the timing and positions of the spawns.

Like Uriel mentioned, you could call GameObject.Destroy() on it. But if you want your game to run smoothly, destroying and spawning enemies could cost a hefty sum of cpu cycles.

One thing you could do is disable gameObject instead. gameObject.active = false. This disables everything on the object. And when you want to respawn the same kind of prefab again, you could reset the object, position it, and gameObject.active = true.

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 Uriel_96 · Nov 29, 2010 at 03:23 AM

you have put something simple like this:

Destroy(enemy,1.0);

first you choose the object you want to destroy and then the other the time that he dies.

And you dont want this use the yield WaitForSeconds() but the problem is that you need to check because when you put it at the end(after enemy is death) is different that put it at the begin.

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 Black Widow 1 · Nov 29, 2010 at 04:49 AM 0
Share

If Enemy is destroyed he is totally gone and cannot be respawned?? is this the case or not. Havn't tried your suggestion as i am still at work will try tonight.

Thanks for the responce

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

1 Person is following this question.

avatar image

Related Questions

Invoke is not like real time 2 Answers

Oncollisionenter and time,OnCollisonEnter and time. 0 Answers

Hide (not delete) text after given time..? 1 Answer

make enemy cars spawn faster over time! 2 Answers

Mining in RTS 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