Джойстик Unity Прыжок

Как сделать так чтобы при прыжке он прыгал не бесконечно, а к примеру 1 раз в 3 секунды?

void Update() {
if(joystick.Vertical > 0.5 && isWallFront && !isGrounded)
        {
            if(transform.rotation.y == 0)
            {
                Jump();
            }
            soundeffector.PlayJumpSound();
        }
        else if (joystick.Vertical > 0.5 && isGrounded)
        {
            Jump();
        }
}
public void Jump()
    {
        rb.velocity = Vector2.up * jumpHeight;//Прыжок
        soundeffector.PlayJumpSound();
    }

Ответы (2 шт):

Автор решения: Максим Фисман

Если вам нужно, чтобы игрок стабильно прыгал раз в три секунды, то:

private IEnumerator () {
    while (true) {
        Jump();
        yield return new WaitForSeconds(3);
    }
}

public void Jump () {...}

Но судя по вашему коду, вам нужно сделать так, чтобы игрок не мог прыгать чаще чем раз в три секунды. Тогда вы можете просто завести счетчик времени.

private float lastTick = 0;
private const int MinJumpDelay = 3;

private void Update() {
    if  (lastTick >= MinJumpDelay) {
        // Можно прыгать
    }
    lastTick += Time.deltaTime;
}

Я бы изменил ваш код следующим образом:

private float lastTick = 0;
private const int MinJumpDelay = 3;

private void Update() {
    if  (lastTick >= MinJumpDelay) {
        if (canJump()) {
            Jump();
        }
        lastTick += Time.deltaTime;
    }

private bool canJump () {
    return joystick.Vertical > 0.5f && 
            (isGrounded || isWallFront && transform.rotation.y > 0);
}
→ Ссылка
Автор решения: Павел

У меня вот так получилось

void Update(){
        if (lastTick >= MinJumpDelay)
        {
            if (canJump())
            {
                Jump();
            }
        }
}
private bool canJump()
    {
        return joystick.Vertical > 0.5f &&
                (isGrounded || isWallFront && transform.rotation.y > 0);
    }
    public void Jump()
    {
        if (isGrounded)
        {
            rb.velocity = Vector2.up * jumpHeight;//Прыжок
            soundeffector.PlayJumpSound();
        }
    }
→ Ссылка