1
\$\begingroup\$

I have hit a problem with my player, I have been following a tutorial on building a platformer. I have put in the UI buttons and linked then to the functions with a script like this:

public GameObject player;// link to player script;
    Player playerVariable; 
    // Start is called before the first frame update
    void Start()
    {
        playerVariable = player.GetComponent<Player>(); 
    }

    public void MobileMoveLeft()
    {
        playerVariable.MobileMoveLeft();
    }

    public void MobileMoveRight()
    {
        playerVariable.MobileMoveRight();
    }

    public void MobileStop()
    {
        playerVariable.MobileStop();
    }

    public void MobileFireGun()
    {
        playerVariable.MobileFireGun();
    }

    public void MobileJump()
    {
        playerVariable.MobileJump();
    }

When I press the up arrow on the keyboard the player jumps and the animation jump is played, but when I press the UI jump button the player still jumps however the jump animation is NOT played.

public void Jump()
{
     if (SantaOnGround)
     {

         SantaOnGround = true;
         rb.AddForce(new Vector2(0, JumpForce));
         Animation.SetInteger("state", 2);
     }
}
\$\endgroup\$
1
  • \$\begingroup\$ Your functions are named MobileJump and Jump. Do you call the same function? \$\endgroup\$ Commented Sep 25, 2019 at 6:17

0

You must log in to answer this question.

Browse other questions tagged .