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 ValeyBeto · May 06, 2014 at 04:25 AM · instantiateyielddelayrespawn

How to delay a respawn?

Hi, I want to respawn a gameObject (player) but I want it to respawn after a few seconds,I'm using the "yield WaitForSeconds()" to do this, but my problem is that after using it nothing happens, it doesn't even reach my debug.log statement. If I take out the "yield WaitForSeconds()" the player respawns as I want, but when I put it back nothing happens. Heres part of the javascript which is in a gamebject that doesn't ever get destroyed:

 var player:GameObject;
 
 function Update(){//this is the position of the undestroyable gameobject
 transform.position=Camera.main.ScreenToWorldPoint( Vector3(Screen.width/2, Screen.height/2, 0) );
 }
 
 function respawn(){
 Debug.Log("hey");
 yield WaitForSeconds(1); 
 Debug.Log("whaaat"); //this debug and the instantiantion doesn't happen 
 Instantiate(player,Vector3(transform.position.x, transform.position.y,0), Quaternion.identity);
 }


I have seen some other questions about how to delay the instantiation but the answers are pretty much the same method I'm using, my question is: why doesn't anything happen after the yield? is there another method to do this?

Comment
Add comment · Show 1
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 thornekey · May 06, 2014 at 04:38 AM 0
Share

If I take out the "yield WaitForSeconds()" the player respawns as I want

you just answered it yourself.. keep it out..

1 Reply

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

Answer by Noob_Vulcan · May 06, 2014 at 04:36 AM

Use

Invoke("respawn",2f); //this will call respawn fun after 2 sec

 function respawn(){
 Debug.Log("whaaat"); //this debug and the instantiantion doesn't happen
 Instantiate(player,Vector3(transform.position.x, transform.position.y,0), Quaternion.identity);
 }
 }


call Invoke("respawn",2f) when your player dies

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 ValeyBeto · May 07, 2014 at 02:24 AM 0
Share

Thank you! it works fine, I was thinking of doing something else using Time.time, but your answer made it much simpler, thanks again Noob_Vulcan

avatar image Noob_Vulcan · May 07, 2014 at 04:38 AM 0
Share

Cool ... Enjoy :)

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

22 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

Related Questions

Delay between each instantiation 3 Answers

Delay in Instantiate only runs once 2 Answers

Inserting a delay 2 Answers

restart level when dead with delay 3 Answers

Coroutine not running after yield return new WaitForSeconds 3 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