- Home /
OnColliderExit2D doesnt seem to execute
Soo, I am making a 2D game and currently was making platforms, managed to make them and I made a script, which when the character gets on top of the platform, he becomes child of it so he moves with it. Now when I wanted to create the exiting platform bit, I found out it just doesn't trigger, for whatever reason. Here is the code, hope it's some silly fast to solve mistake! :D
using UnityEngine;
using System.Collections;
public class MovingPlatformB : MonoBehaviour {
// Use this for initialization
void Start () {
}
void OnCollisionEnter2D (Collision2D other) {
if(other.gameObject.tag == "Player") {
other.transform.parent = transform;
Debug.Log ("fock");
}
}
void OnCollisionExit2D (Collision2D other) {
if (other.gameObject.tag == "Player") {
other.transform.parent = null;
Debug.Log ("???");
}
}
// Update is called once per frame
void FixedUpdate () {
transform.position = MovingPlatform.platformPosition;
}
}
looks ok to me. $$anonymous$$aybe one of your collider is a trigger (isTrigger)?
Answer by Ashish Dwivedi · Feb 06, 2014 at 12:05 PM
If your istrigger property box is unchecked inspector and still OnCollisionEnter2D & OnCollisionExit2D doesn't work then check whether you have added rigidbody to the object or not. Make sure that rigidbody is added to the object.
Actually, neither of the objects has the istrigger checked and OnCollisionEnter2D works, for some reason. The Exit one doesn't.