The question is answered, right answer was accepted
Unity 2D Platformer: Respawn Script Not Working
Hi,
I have read many other posts about this issue but none of which seem to fix it for me. I am trying to make my player object respawn at co-ordinates 0, 0, 0 when it touches a game object which has "Is Trigger" ticked. The game object that should be triggered is called "DeathPoint", it has no tags and is on the "Default" layer.
The DeathPoint Inspector looks like this:
The Player Inspector looks like this:
My C# code is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Respawn : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider other)
{
if (other.name == "DeathPoint") {
other.transform.position = new Vector3 (0, 0, 0);
}
}
}
Thanks!
it's a 2D game. Change from OnTriggerEnter()
to OnTriggerEnter2D()
.
That makes sense, I have rectified that but it still doesn't do anything. I also changed the Collider to Collider2D. void OnTriggerEnter2D (Collider2D other)
Take a screenshot of the other gameObject inspector (the one with the collider).
Answer by xXJamie_Xx · Oct 13, 2017 at 05:37 PM
Issue was solved. Thanks to @tmalhassan!
"Well, you want the player to move then the name should be the Player's object. Change it to this:
if (other.name == "Player")
or you can do it with the tag."