- Home /
Trigger is not detecting Player. (2D)
Trigger is not detecting Player's ship and message is not displaying.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trigger : MonoBehaviour {
void OnColliderStay2D(Collider2D other)
{
if (other.tag == "Ship")
{
Debug.Log("In trigger");
}
}
}
This is not very informative. But you're not using the trigger version for the detection (OnTriggerStay2D)
Answer by Daljit · Sep 17, 2017 at 12:53 PM
You are using the wrong method for detecting collision detection. Try the following method.
void OnCollisionStay2D(Collision2D col)
{
if(col.gameObject.tag == "Ship")
{
Debug.log("In Trigger");
}
}
Unity Documentation OnCollisionStay2D
It work but only while I use collider not trigger. I want to make trigger area.
Your answer
Follow this Question
Related Questions
2D Platformer - Picking Up Items & Storing Them C# 0 Answers
GameObjects glitching through other Objects when being held 0 Answers
How can I detect a collision point, but allow player to pass through collider. 1 Answer
How to make work a collision when is invisible? 3 Answers
How do you execute Trigger-collider collision only in one gameobject? 1 Answer