0

I made a coroutine that makes the player jump in the game it works when I use the normal "input.getkey" way but when I click a button that calls a void which then starts the coroutine that controls the jump , but it doesn't jump at all the only code it executes in the coroutine is Debug.Log

public void ButtonUp()
    {
        if (onGround == true) { Debug.Log("wtf");  StartCoroutine(Jump()); }
    }

    IEnumerator Jump()
    {
        testint++;
        Debug.Log("wtf 2");
        player.position += new Vector3(0, .5f, 0 * Time.deltaTime);
        player.position += new Vector3(0, .5f, 0 * Time.deltaTime);
        player.position += new Vector3(0, .5f, 0 * Time.deltaTime);
        player.position += new Vector3(0, .5f, 0 * Time.deltaTime);
        player.position += new Vector3(0, .5f, 0 * Time.deltaTime);
        player.position += new Vector3(0, .5f, 0 * Time.deltaTime);
        testint++;

        onGround = false;
        yield return new WaitForSeconds(.62f);
        onGround = true;
    } 

yes I know how inefficient my code is.

iv tried the button in playtesting ( I saw that the testint value also doesn't change ) and only debug.log works it also doesn't matter if it's in the first line of the coroutine this is not the only situation the move left and move right buttons also have the same issue for me

( "wtf2" and "wtf1" gets debug into console )

here's the code for the keypress coroutine start

        if (Input.GetKeyDown(KeyCode.Space) && onGround == true) { StartCoroutine(Jump()); }

Unity Version - 2020.3.18f1 Personal* DX11

Mirazz_Boi
  • 13
  • 1
  • 3
  • Do you have a rigidbody attached to the player? And are there any error messages? – Cyclone6664 Jun 19 '22 at 16:57
  • NVM turns out I am extremely stupid and I had put movement script on the button then executed the script in the button instead of the player – Mirazz_Boi Jun 20 '22 at 12:51

0 Answers0