- Home /
2D Platformer Reload Game On Collision With Sprite
Hello, I am trying to make a script that I can place within a 2D sprite that has a boxcollider2D within it in my 2D platformer. I have been trying to make it reload the level when the player touches the object. I have been trying this script but I can't get it to work. What am I doing wrong?
public class Restart : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
Answer by MUGIK · Jul 14, 2016 at 07:21 AM
You using OnTriggerEnter2D so at least one of your colliders (boxcollider2D or player Collider) must be trigger (isTrigger in inspector). And if any collider in your game moving at runtIme you must attach Rigidbody2D to this gameObject.
Your answer
Follow this Question
Related Questions
2d Platformer Jumping Not Working 1 Answer
2D - Detect Slopes x Walls 1 Answer
Pushing against Edge Collider wall stops player from falling 0 Answers
Why does my OnCollisionEnter2D not work? 3 Answers