Hello everyone…
I’m new to unity here and i am experiencing something strange with OnColiisionEnter2D.
I want to make a platformer game which the character can only jump from one floor to another. I have three objects. First is moving floor which contains script to move from right to left. Second is regular floor with no script attached. Third is the character itself.
This is my script for character movement :
public float jumpForce;
public bool enableJump = true;
void Update() {
if (enableJump == true) {
if (Input.GetMouseButtonDown (0)) {
rigidbody2D.velocity += jumpForce * Vector2.up;
enableJump = false;
}
}
}
void OnCollisionEnter2D (Collision2D collision) {
if (collision.gameObject.tag == "floor") {
enableJump = true;
}
}
}
I use same tag for those two kinds of floor.
The rule is character cannot do double jump. This script works fine with regular floor, but it doesn’t work in moving floor. Character can do double jump after touch moving floor.
Can anyone help me with this problem?
Thank you and sorry for my bad english.