The question is answered, right answer was accepted
OnCollisionEnter2D not being called
Ok so, i'm about to have a mental breakdown. Here's what i'm trying to do: basically I'm trying to have a game object that will spawn a particle effect and will destroy himself once picked up (something never done ever before). The code is: ## using UnityEngine; using System.Collections;
public class FruitPickup : MonoBehaviour {
private BoxCollider2D m_boxcollider;
public LayerMask Player;
public Transform m_particles;
void Awake () {
m_boxcollider = GetComponent<BoxCollider2D> ();
}
void OnCollisionEnter2D (Collision2D coll) {
if (coll.gameObject.tag == "Player") {
Debug.Log ("Yup!");
}
}
void PickUp () {
Debug.Log ("Fruit Obtained");
Destroy (gameObject, 0.05f);
}
}
The "Yup!" debug.log is not being called, I checked the sintax a million and a half times so I'm pretty sure that the problem is not in there.. The player object is tagged as Player, so the problem is not there either. My best bet is that i'm misunderstanding how "OnCollisionEnter2D" works, but I wasn't able to find any answer to my problems, sooo.. Help..? Anyone? Thanks to anyone patient enough to read all this moaning!
edit: Guess what, I was stupid! For a trigger collider I need "OnTriggerEnter2D", not "OnCollisionEnter2D".
Answer by FeeeshMeister · Sep 05, 2016 at 06:40 PM
Make sure that the player has a rigidbody, if it does then adjust the settings, make sure isKinematic is turned on, etc. Sometimes it even works just to remove the rigidbody and add it again, PhysX is a bit unstable sometimes.
Follow this Question
Related Questions
Cant figure out how to make a pickup that swaps one game object for another. 0 Answers
Animator and collision issues 0 Answers
Adding different values to randomly created objects 0 Answers
[SOLVED] Problem with OnCollisionEnter2D script after upgrading to Unity 5.3(from Unity 4.6) 1 Answer
create object on raycast collision that follows raycast. 0 Answers