Where do i put an if- bool statement in to make it run one times.

i’m making some 2d platformers


the problem i stuck here with is the dash and jump mechanic

there is dash script for dash
and playermovement for jump

i just want it to add +1 jump after you’ve dashed in mid air


so, i set a bool in dash script , and when i dashed the bool isDashing from false will become true and after sometimes it will return to false state again

and then i go to playermovement script, pull component from Dash script.
put the if statement that

if(Dash.isdashing ==true)
{print (“someword”);


when i put it in void update of playermovement script, the “someword” will print countless times, and i want it to print just one times.

i tried to create new public method in playermovement and put the code above in, it never print out anything.


i know its a simple question but i’m so stressed out right now. Can someone enlighten me.

Hi!

So, since your aim is to add +1 jump afted dash that your character could jump again, I assume, you can simply toggle is_CanJump boolean if you are using one.

Imagine your jump script looks something like this:

public bool is_CanJump;
bool is_Grounded;

void Update()
{
    if(Input.GetKeyDown(KeyCode.Space) && is_CanJump)
    {
        /* Jump code */
        is_CanJump = false;
    }
}

void OnCollisionEnter2D(Collision2D col)
{
    if (col.collider.CompareTag("Ground"))
    {
        is_Grounded = true;
        is_CanJump = true;
    }
}

Where you have functions for ground checking and you can jump when your is_CanJump boolean set to true. So, after dash you can simply toggle is_CanJump to true therefore you will be able to execute Jump again.


Hope it helps.