- Home /
Question by
Powarader · Aug 09, 2015 at 04:04 PM ·
collision2d
OnTriggerEnter2D only calling once
void OnTriggerEnter2D (Collider2D any) {
if (any.tag == "Circle") {
if (any.gameObject.GetComponent<SpriteRenderer> ().sprite == redState && this.gameObject.GetComponent<SpriteRenderer> ().sprite == redState) {
Debug.Log ("Both Red!");
}
if (any.gameObject.GetComponent<SpriteRenderer>().sprite == redState && this.gameObject.GetComponent<SpriteRenderer> ().sprite == whiteState) {
Debug.Log ("White and Red!");
}
}
}
This function is calling only once, when two red circles collide again, it doesn't log, or when is red and another is white... Why is that?
Comment
Use OnTriggerStay to continuosly detect collisions:
http://docs.unity3d.com/ScriptReference/Collider.OnTriggerStay.html
Best Answer
Answer by Eric5h5 · Aug 17, 2015 at 01:42 AM
Turn off "collapse" in the console, or look at the right where the number in the circle tells you how many times each message is repeated.