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 EuerUhlchen · Jul 27, 2020 at 11:51 AM · respawning

how to let my charactere respawn

I started programming my very own Platformer, and now came to a point where i wanted to add a respawn area into my game, if you fall down. so I watched a video on YouTube and recreated it, but its not working in my case. If someone would help me I would appreaciate it a ton : )

So, here is my code, thanks for helping:

First the Player code with the respawn trigger stuff at the bottom: using System.Diagnostics; using UnityEngine; public class Player : MonoBehaviour {

[SerializeField] private LayerMask platformsLayerMask;
private Rigidbody2D rigidbody2d; private BoxCollider2D boxCollider2d; private Animator animator;

public GameManager theGameManager;

public Joystick joystick;

float horizontalMove = 0f;

private void Awake() { rigidbody2d = transform.GetComponent(); boxCollider2d = transform.GetComponent(); }

 private void Update() {
    if (IsGrounded() && Input.GetKeyDown(KeyCode.Space)) {
          float jumpVelocity = 20f;
          rigidbody2d.velocity = Vector2.up * jumpVelocity;

    }
    
    HandleMovement();

}

 private void OnTriggerEnter2D(Collider2D other)
 {
     if(other.gameObject.CompareTag("Coins"))
     {
         Destroy(other.gameObject);
     }
 }



private bool IsGrounded() { RaycastHit2D raycastHit2d = Physics2D.BoxCast(boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down, .1f, platformsLayerMask);

   return raycastHit2d.collider != null;

}

private void HandleMovement() { float moveSpeed = 12f;

   rigidbody2d.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, rigidbody2d.velocity.y);

}

public void ActionJump() {

    rigidbody2d.AddForce(transform.up * 400f);
   animator.SetTrigger("jump");

}

 void onCollisionEnter2D (Collision2D other)
 {
     if(other.gameObject.tag == "killbox")
     {
         theGameManager.RestartGame();
     }
 }
  

  
   

}

And also here my respawn Game Manager code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class GameManager : MonoBehaviour {

 public Transform LevelGenerator;
 private Vector3 platformStartPoint;

 public Player Player;

 private Vector3 playerStartPoint;






 // Start is called before the first frame update
 void Start()
 {
     platformStartPoint = LevelGenerator.position;
     platformStartPoint = Player.transform.position;
     
 }

 // Update is called once per frame
 void Update()
 {
     
 }

 public void RestartGame()
     {
         StartCoroutine ("RestartGameCo");


     }
     

     public IEnumerator RestartGameCo()
     {       

             yield return new WaitForSeconds(2f);
             Player.gameObject.SetActive(false);
             
             Player.transform.position = playerStartPoint;
             LevelGenerator.position = platformStartPoint;
             Player.gameObject.SetActive(true);


     }
 

}

So thank you for helping its really really kind : )

Also I just want to say: yes the Respawn Trigger got the killbox tag, also everything is filled in and yeah I really did everything but it is still not working

Thanks for the help : )

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 canslp · Jul 27, 2020 at 12:32 PM

wait so which part isn't working. can you detect collision with the respawn area?

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 EuerUhlchen · Jul 27, 2020 at 12:38 PM 0
Share

if my charactere falls on the rspawn trigger/ respawn area the box collider works, its visibel but nothing happens

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

205 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 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

Sprite becomes invisible after spawn 0 Answers

ThePlayer should respawn at his start position after his health drops down to 0. However it doesn't work properly. Can somebody tell me what went wrong and how to fix it please? 0 Answers

How do I respawn something after it's been disabled? 0 Answers

Impact on Top vs Side and Respawn 0 Answers

How to Respawn an gameObject when it touch another gameObject 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