Hi, I’ve written a script where if my player collides with anything with the tag “Obstacle” then it should die and the scene should reset. However, when the player and obstacle collide, nothing happens, the game carries on as if there’s no script. Both the player and obstacle have colliders, here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerDeath : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "Obstacle")
{
Debug.Log("You Died!");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}