viewimage.php?id=2abcdd23dad63db0&no=24b0d769e1d32ca73fef80fa11d028314d28878c8e439571894d71b564e0c7c6dcd3f34f3353c9ff344bea8659a77815459eaac34cbae23a782323ce0adda14c07a7




using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class PlayerMovement : MonoBehaviour

{


    [SerializeField] private float speed;

    [SerializeField] private float jumpForce;

    [Range(0, .3f)] [SerializeField] private float m_MovementSmoothing = .05f;

    [SerializeField] private Transform groundCheck;

    [SerializeField] private LayerMask whatIsGround;

    [SerializeField] private Animator animator;


    const float checkRadius = 0.1f;

    private float moveInput;

    private Rigidbody2D rb;

    private bool facingRight = true;

    private bool isGrounded = false;

    private bool jump = false;

    private int extraJumps = 1;

    private Vector3 refVelocity = Vector3.zero;

    bool isCheck;


    void Start()

    {

        rb = GetComponent<Rigidbody2D>();

        isCheck = true;

    }


    void FixedUpdate()

    {

        if (isCheck)

        {

            Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheck.position, checkRadius, whatIsGround);

            for (int i = 0; i < colliders.Length; i++)

            {

                if (colliders[i].gameObject != gameObject)

                {

                    Debug.Log(colliders[i].gameObject.name);

                    isGrounded = true;

                    animator.SetBool("Jump", false);

                    animator.SetBool("Jump2", false);

                    jump = false;

                }

            }

        }


        moveInput = Input.GetAxisRaw("Horizontal");

        Vector3 targetVelocity = new Vector3(moveInput * speed * Time.fixedDeltaTime, rb.velocity.y);

        rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref refVelocity, m_MovementSmoothing);


        if (jump == false)

        {

            animator.SetFloat("Speed", Mathf.Abs(moveInput) * speed);

        }


        if (facingRight == false && moveInput > 0)

        {

            Flip();

        }

        else if (facingRight == true && moveInput < 0)

        {

            Flip();

        }

    }

   

    void Update()

    {

        if (isGrounded == true)

        {

            extraJumps = 2;

        }


        if (Input.GetButtonDown("Jump") && extraJumps == 2)

        {

            Jump();

          

        }else if (Input.GetButtonDown("Jump") && extraJumps == 1)

        {

            Jump();

        }

    }


    IEnumerator Jump_()

    {

        extraJumps--;

        isCheck = false;

        if (extraJumps == 1)

        {

            animator.SetBool("Jump", true);

        }

        if (extraJumps == 0)

        {

            animator.SetBool("Jump2", true);

        }

        jump = true;

        isGrounded = false;

        rb.velocity = new Vector2(rb.velocity.x, jumpForce);

        yield return new WaitForSeconds(0.1f);

        isCheck = true;

    }


    void Jump()

    {

        StartCoroutine("Jump_");

    }


    void Flip()

    {

        facingRight = !facingRight;

        Vector2 theScale = transform.localScale;

        theScale.x *= -1;

        transform.localScale = theScale;

    }

}


점프가 왜 안됐냐 하니까 저 그라운드 체크가 바로 이어져있어서 점프하자마자 점프를 페일 시켜버리더라 그래서 첫번째는 안되고 두번째는 점프모션 나오던거 ....


2단 점프라서 점프 모션 하나 더 복제해서 셋불 jump2 라고 따로 하나 만들었다 애니메이터 연결은 player_jump에서 player_Jump2 로 jump2 를 연결해주고 


player_Jump2 에서 Player_Idle 로 jump false 연결 해주고 player_Jump2에서 Player_Run 으로 jump false 랑 speed greate 0.01 연결해줬당 ㅇㅇ


그리고 jump 랑 jump2 에서 player_Idle 로 연결되는부분에 speed less 0.01 이건 때버렸다 ㅇㅇ


그리고 케릭터 밑으로 빠진다는건.... 난 안빠지고 잘 되더라 ????


그래서 그건 수정 못했음 ㅇㅇ 


암튼 그럼 즐뎁 수공!