- Home /
Question by
arturoza · Aug 19, 2014 at 05:26 PM ·
triggerfunctionboxcollider
Jump function not working
Hi, I have a player (with boxcollider2d and rigibody2d) with this script, In another gameobject I put boxcollider2D with "is trigger" and when the player enter the trigger it displays the message "Entered" and "Exited" but it doesn't do the function I assigned, here's the script, I hope you can help me.
public class PlayerController : MonoBehaviour {
float jumpHeight = 7f;
bool trigger = false;
void FixedUpdate ()
{
rigidbody2D.velocity = new Vector2(1, rigidbody2D.velocity.y);
if (trigger == true)
{
Jump ();
}
}
void Jump()
{
rigidbody2D.AddForce (new Vector2(0, jumpHeight));
}
void OnTriggerEnter2D (Collider2D other)
{
if (other.transform.tag == "trigger")
{
trigger = true;
Debug.Log ("Entered");
}
}
void OnTriggerExit2D (Collider2D other)
{
if (other.transform.tag == "trigger")
{
trigger = false;
Debug.Log ("Exited");
}
}
}
Comment
Best Answer
Answer by arturoza · Aug 19, 2014 at 05:30 PM
Hi, so stupid of me, I had a typo in the tag, It works