How to set Player to push only during pushing animation

Hey Guys

I’ve setup my script so that I can push a crate and it works, however it pushes simply when I walk into it, I’ve managed to edit it so that it now pushes when using the push animation (Holding “Fire1”), and pushes much slower according to my pushing speed.

However I can’t work out how to set it so that it only moves when I’m pushing it intentionally.

I’ve placed my script below, if anyone has any advice It’d be greatly appreciated.

    // this script pushes all rigidbodies that the character touches
    var pushPower = 2.0;
    var weight = 6.0;
    function OnControllerColliderHit (hit : ControllerColliderHit)
    var body : Rigidbody = hit.collider.attachedRigidbody;
    var force : Vector3;
    // no rigidbody
    if (body == null || body.isKinematic) { return; }
    // We use gravity and weight to push things down, we use
    // our velocity and push power to push things other directions
    if (hit.moveDirection.y < -0.3 && Input.GetButton ( "Fire1" )) {
    force = Vector3 (0.1, -0.5, 0) * 1 * weight;
    } else {
    force = hit.controller.velocity * pushPower;
    // Apply the push
    body.AddForceAtPosition(force, hit.point);

Thankyou dorpeleg, it was staring me right in the face but I couldn’t see it.