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 Noaal · May 06, 2014 at 06:55 AM · resetcheckpoint

Restarting game from last checkpoint.

Hello, I'm making some basic platformer game and I have one issue. To control if my player dies I have gameobject with Destroyer method and then Application.LoadLevel().When player dies screen appears with restart button. What I want to acomplish is to when player pass checkpoint and dies I want him to be spawned in checkpoint location. I made some basic code to store player position but I have no idea what to do next. public class Checkpoint : MonoBehaviour {

 Vector3 playerPos;

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player") 
     {
         playerPos = other.transform.position;



     }
 }



}

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 Jellezilla · May 06, 2014 at 07:04 AM 0
Share

You could create a gameobject that would be the lastCheckpointReached. Whenever your player reaches a new waypoint, then you set lastCheckpointReached = waypoint;

Whenever the player dies, then you have stored the position of the checkpoint in the gameobject above and can just set the position of your player to be equal to the lastCheckpointReached position: if(other.tag == "Player") { other.transform.position = lastCheckpointReached.transform.position; }

1 Reply

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

Answer by fafase · May 06, 2014 at 07:02 AM

You should not destroy your player, more likely disable renderer or trigger death animation and then reposition him.

To respawn, you almost got it.

In your player, where you have the death method add a Transform for respawn.

Then when you enter the trigger box:

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player") 
     {
        other.gameObject.GetComponent<ComponentWithDeath>().respawn = this.transform; 
     }
 }

And your death method is something like:

 public Transform respawn = null;
 IEnumerator Death(){
    float wait = 0;
    // Here get the guy dying in animation or else
    while(wait < 3){
        wait += Time.deltaTime;
        yield return null;
    }
    if(respawn != null){
       transform.position = respawn.position;
       transform.rotation = respawn.rotation; // Make sure the box is orientated to the right
    }
 }

The method above will get the player to wait for 3s before being respawn. You will need to add more details, as for the health, maybe some blinking at first, and other things.

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

20 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

Related Questions

Reset a scene but save checkpoints. 2 Answers

Problem naming instances with incrementally numbered counter 1 Answer

Help With Simple Rotation 4 Answers

Programming A Reset Scene 0 Answers

this script is to reset the ball to its initial position after every kick in foorball game.. 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