- Home /
The question is answered, right answer was accepted
C# Collision Script Not Working
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);
}
}
}
Answer by ShadyProductions · Jul 30, 2018 at 11:17 AM
Do the colliders have IsTrigger as true? and are they 2D Colliders?
Ah, I just made them triggers and it's working now, thanks man!
Follow this Question
Related Questions
[SOLVED]Problem with 2D Collider 0 Answers
Sprite image not changing 0 Answers
How do I make an object move out of another object? 1 Answer
Enemies Jump at Random with Coroutines 2d (C#) Error. 0 Answers