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 Toy · Mar 06, 2012 at 02:16 PM · spawnrespawndeath

Respawning my AVATAR

Hi there, I have a script spawning my player at the beginning of the game.

When my player dies ( when falling from more than 8 meters ).

My respawn is not working.

Any idea to help me ?

Thank you...

Here is my script:

public class DeathRecognition : MonoBehaviour

{

 public Transform spawnPoint;
 
 public bool falling = false; 
 public float lastY;            // last grounded height
 public float hauteurChute;    //    ce ki cause ma mort
 public CharacterController  character;    //    sera eventuellement detruit
 private float deathFall = 7.632f;    // pour etre constant de mon 8 m de map...
                                     // lavatar glisse un peu sur les parois (+/- 0.30)
 
 void spawn()
 {        
     transform.position = spawnPoint.position;
 }
 void Start()
 {
     spawn();
 }
 
 
 void Update()
 {
     
       if (character.isGrounded == false)    // est en train de tomber sans avoir saute
     {
         hauteurChute = lastY - transform.position.y ;
         if (hauteurChute < 0) lastY = this.transform.position.y;    //    si je suis en train de sauter
                                                                     //    la valeur la + haute de mon saut
      }
     else 
     {
         if ( hauteurChute > 0.5 )
         {
             Debug.Log("Hauteur du saut :"+ hauteurChute);    //    hauteur de mon saut
         }
         
         if ( hauteurChute >= deathFall )
         {
             Debug.Log("DEAD");
             Die();
             
         }
         hauteurChute = 0.0f;                //    si ma chute n<est pas mortelle
         lastY = this.transform.position.y;    //    je reinitialise ma chute a 0
     }
  }
 
 
 void Die()
 {
     Destroy(gameObject);
     spawn();
 }

}

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 syclamoth · Mar 06, 2012 at 02:25 PM

Basically, the problem is here:

 void Die()
 {
     Destroy(gameObject);
     spawn();
 }

This will first destroy the object, and then call 'spawn' which moves the transform back to the spawnPoint.

However, because the object gets destroyed first, it won't work! The object gets moved to the spawn point, and then disappears before the next frame begins.

If you just want the player to move back to the spawn, remove the 'Destroy' line.

If you want it to create a new player after destroying the old one, try instantiating a prefab, or in fact calling

 Instantiate(gameObject);

which will create a perfect copy of the character.

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 Toy · Mar 06, 2012 at 02:38 PM 0
Share

By doing this, more than one player comes back to life meaning it is not working :(

avatar image syclamoth · Mar 07, 2012 at 12:35 AM 0
Share

What's creating the second one? I meant you should either instantiate a copy or remove the Destroy line, not both!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I want to create a radiation scall in the top corner that continues going up until you get to the end of the map. I then want the player to die if the scale reaches the end and they havent reached the end of the map 0 Answers

How do I randomize the order of spawn points without repeats? 1 Answer

Gameobject Respawn 1 Answer

Player Respawn After Death 1 Answer

Array index out of Range 1 Answer


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