- Home /
Question by
Lava_Key · Feb 10, 2020 at 09:09 AM ·
2d-platformer
2D platformer respawn problems
I've been making a 2D platformer I unity with c# and I followed SpeedTutors video on Dying and Respwaning. But when ever any object touches the "Death Box" the player is teleported. Does anyone know how to fix this?
Here's the code I'm currently using:
[SerializeField] private Transform Player;
[SerializeField] private Transform RespawnPoint;
void OnTriggerEnter2D(Collider2D other)
{
Player.transform.position = RespawnPoint.transform.position;
}
Comment
Best Answer
Answer by Klarax · Feb 10, 2020 at 09:13 AM
you'll need a check to see if the player entered is the player
something along the lines of
//checks against its name - must be player on this case
void OnTriggerEnter2D(Collider2D other)
{
if(other.name == "Player") //change player to whatever your player is called
{
Player.transform.position = RespawnPoint.transform.position;
}
}
or
//checks against a tag
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag== "Player")
{
Player.transform.position = RespawnPoint.transform.position;
}
}
Your answer
Follow this Question
Related Questions
Newbie question about infinite runners 0 Answers
Hit/React Animation 2 Answers
OnTriggerEnter2D(Collider2D other) 2 Answers
Changing a variable from a different method 1 Answer
Add audio. 1 Answer