Why is my definition for OnCollisionEnter () not used?

I have a symbol that the boolean flag determines if it is jumping (if it is jumping, it cannot jump again). When it jumps, the transition flag is set to true, and when it encounters something, it returns to false (so it can jump again).

However, it only jumps once, and the jump remains true, even if it should reset to false. Why is this so? My definition for OnCollisionEnter()suggests resetting the flag.

var trump;
var jump = false;

function Start() {
// Assigns the Rigidbody to a variable
trump = GetComponent(Rigidbody2D);
// Variable Switches:

}

function OnCollisionEnter() {
    jump = false;
    trump.velocity.y = 0;
    trump.velocity.x = 0;
}

function FixedUpdate() {
    trump.velocity.x = Input.GetAxis("Horizontal") * 10;
    if ((Input.GetKeyDown(KeyCode.UpArrow)) && (jump == false)) {
        trump.AddForce(Vector2(0, 10), ForceMode2D.Impulse);
        jump = true;
    }
}

EDIT: Based on the answer, I tried adding the parameter Collisionto OnCollisionEnter(), but it still does not look like the function is being called after I added a Debug.Log()check inside this. Is something else wrong?

function OnCollisionEnter(collision: Collision) {
    jump = false;
    Debug.log("He Hit The Wall");
    trump.velocity.y = 0;
    trump.velocity.x = 0;
}

enter image description here

+4
1

OnCollisionEnter(). , MonoBehaviour, , . MonoBehaviour , , .

OnCollisionEnter() Collision:

function OnCollisionEnter(collision: Collision) {
    jump = false;
    trump.velocity.y = 0;
    trump.velocity.x = 0;
}

. , - , OnCollisionEnter() .

- Unity 2D, , 2D- : OnCollisionEnter2D, a Collision2D.

, :

function OnCollisionEnter2D(collision: Collision2D) {
    jump = false;
    trump.velocity.y = 0;
    trump.velocity.x = 0;
}

, ! , .

+4

All Articles