using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class KeyPressChangeAni : MonoBehaviour

{

    public string player = "";

    public string left = "";

    public string right = "";

    string nowMode = "";

    public float speed = 2;

    public float jumppower = 4;


    float vx = 0;

    bool pushFlag = false;

    bool jumpFlag = false;

    bool groundFalg = false;


    Rigidbody2D rbody;

    

    void Start()

    {

        rbody = GetComponent<Rigidbody2D>();

        rbody.constraints = RigidbodyConstraints2D.FreezeRotation;

        nowMode = player;

    }


    // Update is called once per frame

    void Update()

    {

        if (Input.GetKey("left"))

        {

            nowMode = left;

            vx = -speed;

           

          

        }

        if (Input.GetKey("right"))

        {

            nowMode = right;

            vx = speed;


        }

        if (Input.GetKeyUp("left"))

        {

            nowMode = player;

            vx = 0;

        }

        if (Input.GetKeyUp("right"))

        {

            nowMode = player;

            vx = 0;

        }

       

        if (Input.GetKey("space")&&groundFalg)

        {

            

            if(pushFlag==false)

            {

                jumpFlag = true;

                pushFlag = true;

                

            }

            

        }else

        {

            pushFlag = false;

        }

        


    }

    void FixedUpdate()

    {

        rbody.velocity = new Vector2(vx, rbody.velocity.y);

       

        this.GetComponent<Animator>().Play(nowMode);

        this.transform.Translate(vx / 50, 0, 0);

        


        if(jumpFlag)

        {

            jumpFlag = false;

            rbody.AddForce(new Vector2(0, jumppower), ForceMode2D.Impulse);

            

        }

    }

    void OnTriggerStay2D(Collider2D collision)

    {

        groundFalg = true;

    }

    void OnTriggerExit2D(Collider2D collision)

    {

        groundFalg = false;

       

    }

}


점프까지 구현했는데 점프하면서 오른쪽 키를 누르거나 왼쪽 키를 누르면 점프하면서 그 방향으로 움직여지네요 점프 도중에는 점프만 해야할텐데 아무리 수정해도 잘 되지 않아서 질문 다시 올립니다..