Quantcast
Channel: Answers for "Detect a collision but allow prefabs to pass through each other"
Viewing all articles
Browse latest Browse all 4

Answer by thornekey

0
0
Check the "IsTrigger" button in the inspector on your collider component. Your tag suggests it's a 2D game.. so: void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "YourTag") { Debug.Log("Its a hit!"); } } but!, for 3D: void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "YourTag") { Debug.Log("Its a hit!"); } } and if you want to check whether is has left the trigger change "Enter" to "Exit"! http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerExit2D.html Good Luck!

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images