I have a colider error
whenever i run my script called HoldPlayer i get this error and my script cant run. The goal of this script is to keep the player on a moving platform
my script
public class HoldPlayer : MonoBehaviour {
void OnTriggerEnter(BoxCollider2D col2D) {
col2D.transform.parent = gameObject.transform;
}
void OnTriggerExit(BoxCollider2D col2D) {
col2D.transform.parent = null;
}
}
please format ALL of your code.
and which error? post the complete error message...
it was in the unity console, it said
Script error: OnTriggerEnter This message parameter has to be of type : collider
Script error: OnTriggerEnter This message parameter has to be of type : collider
Script error: OnTriggerExit This message parameter has to be of type: Collider The message will be ignored.
Answer by brunocoimbra · Jan 27, 2016 at 06:36 PM
You trigger method is incorrect, as the message itself says... If you are using the 2D physics, use:
void OnTriggerEnter2D(Collider2D col2D) {}
void OnTriggerExit2D(Collider2D col2D) {}
Attention: The paramenter is a Collider2D, not a BoxCollider2D. Also, if you are using the 3D physiscs (without the 2D), just delete the "2D" both from the method and from the parameter.