Enable/Disable a certain part of program

Hey guys!

Let me Get Straight to the point.

The problem with my code is, that I have two scripts: One for the movement and other is the animation controller. Also, im using raycast for my jump.
So, basically the first program moves and controls jumps.
The other one will disable the jump in the first one. The problem is, that the player
will just jump with repeated UpArrow taps,and will also climb walls with the same.
Is there any way to AVOID doing this?

Code:
//Player Code
var units = 2.0;
var CanJump = true;
var PlayerCollider : GameObject;

function Update()
{
//player movements in game area
//move the player ahead
MyAnimatedModel.animation.Play(RunAnimation.name);
transform.position += transform.forward * units * Time.deltaTime;
if (CanJump != false);
{//jumping system
if (Input.GetKeyDown (KeyCode.UpArrow)){
rigidbody.AddForce(PlayerCollider.transform.up * 250, ForceMode.Acceleration);
MyAnimatedModel.animation.Play(PlayerJumpAnimation.name);
}
}
}

Here is script #2

// Animation/Movement moderator and controller
var ThePlayer : GameObject;
var Air : String;

function OnTriggerEnter( other : Collider ) {
    Debug.Log("Collision Signal Detected");
    if (other.tag == Air) 
    {
        ThePlayer.GetComponent(MoveScript).CanJump = false;  
    }
}

UPDATE:The collision is detected, but the jumping part is not disabled

P.S It would look good as a flappy bird game with my so-called working program, but that's not what I want. What I want is this.

You have a small typo

if (CanJump != false);

The semicolon closes the if-block so that you’re always running the code following it.

Also when you’re dealing with booleans, you can just write

if (CanJump)
{
      // we do this if we can jump
}

In my opinion that’s much more readable :slight_smile: