Call Function with a Bool (C#)

Hello, I’m trying to create a Power-Up system that when you collect an object, an upgrade is applied. I am doing this through two different scripts. I have the player movement script that adds the “Dash” upgrades to the character. I am trying to only activate the function that handles the “Dash” when the object is collected. I am unsure of how to do this. Any help will be greatly appreciated.

To clarify I have a Power-Up script applied to the collectible object, and I have the Character Movement script applied to the player. I am only trying to call one (1) function from the Character Movement script and make it active ONLY when the object is collected, else it is not active.

Character Move Script:

void Start()
{
    characterController = GetComponent<CharacterController>();
    //powerUp.Pickup();
    
}

void Update()
{

    if (characterController.isGrounded)
    {
        // We are grounded, so recalculate
        // move direction directly from axes

        moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));

        moveDirection *= speed;

        //Point Player in Direction 
        transform.LookAt(transform.position + new Vector3(moveDirection.x, 0, moveDirection.z));

        if (Input.GetKey(KeyCode.W) || (Input.GetKey(KeyCode.S)) || (Input.GetKey(KeyCode.A)) || (Input.GetKey(KeyCode.D)))
        {
            //anim.Play("LittleRun");
            anim.SetInteger("RunIdle", 1);

            if (Input.GetButton("Jump"))
            {
                moveDirection.y = jumpSpeed;
                anim.SetInteger("RunJump", 2);
            }
            else
            {
                anim.SetInteger("RunJump", 0);
            }
        }
        else
        {
            //anim.Play("LittleIdle");
            anim.SetInteger("RunIdle", 0);
        }

        //Make Player Jump
        if (Input.GetButton("Jump"))
        {
            moveDirection.y = jumpSpeed;
            anim.SetInteger("JumpIdle", 1);
        }
        else
        {
            anim.SetInteger("JumpIdle", 0);
        }
    }

    else if (characterController.isGrounded == false)
    {
        moveDirection.x = Input.GetAxis("Horizontal") * speed;
        moveDirection.z = Input.GetAxis("Vertical") * speed;
        //Point Player in Direction 
        transform.LookAt(transform.position + new Vector3(moveDirection.x, 0, moveDirection.z));
        DashMove();
        
    }

    // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
    // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
    // as an acceleration (ms^-2)
    moveDirection.y -= gravity * Time.deltaTime;

    // Move the controller
    characterController.Move(moveDirection * Time.deltaTime);
}

public void DashMove()
{
//Dash
if (Input.GetKey(KeyCode.LeftShift))
{
moveDirection.z = Input.GetAxis(“Vertical”) * dashSpeed;
moveDirection.x = Input.GetAxis(“Horizontal”) * dashSpeed;
dash.Play();

    }
    
}

}

Power-Up Script:

public void Start()
{
    characterMove.DashMove();
}

void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        Pickup();
    }
}

public void Pickup()
{
    //Spawn Cool Effect
    Instantiate(pickupEffect, transform.position, transform.rotation);
    //Apply Effect to Player
    characterMove.DashMove();
    // Remove Object
    Destroy(gameObject);
    
}

}

You could add bool to the player that checks if you can use your dash action. Then add a public method that can be called from your pickup to set if you can dash or not. Something similar to the following:

private bool canDash = false;

// Can be called by pickups
public void SetCanDash(bool value) {
	this.canDash = value;
}

Then you can use that bool in your DashMove method to check if you should handle the dash logic.

public void DashMove() { 
// Exit early cause player cant dash yet
if (this.canDash == false)
	return;

// Dash Code Here
}