- Home /
Trigger not working 2D
Hello, I'm working on a simple 2D tower defense game. I'm very new to Unity.
I have a Tower Game Object with a Circle Collider, simulating the shooting range.
Right now i only want to get a message when an Enemy enters my range. But nothing works
This is my tower
and this is my enemy
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tower_Collider : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
Debug.Log(" TRIGGER ENTERED");
}
void OnCollisionEnter(Collision col)
{
Debug.Log("COLLISION DETECTED");
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
What am I doing wrong?
Answer by tanoshimi · Dec 17, 2016 at 11:17 PM
You should be using
void OnTriggerEnter2D(Collider2D other)
not
void OnTriggerEnter(Collider other)
Tanoshimi is correct. OnTriggerEnter is for 3D physics elements...OnTriggerEnter2D is for 2d Physics elements.
Also, Tower_Collider will never receive OnTriggerEnter2D events has it is not a Trigger.
It has a trigger. Look at the top screenshot.
You're right, I got confused as the other object also has the same component.
Your answer
Follow this Question
Related Questions
How can I disable this collider, when two are present on the gameobject 1 Answer
Select collider for GetComponent? 1 Answer
How to detect which side of a box collider was hit? (Top, Bottom, Right, Left) 2D game/ C# 3 Answers
Checking gameobject in Collider range only on method call 1 Answer
Which setup should I use for spawning? 0 Answers