티스토리 뷰

💻 Unity

Blend Tree (두 개 이상 애니메이션 합쳐서 사용)

Friction(마찰력) 없애기

Friction 0으로 한 후 Rigidbody에 넣어줌


🕹️ 실습 (2D 횡스크롤 2)

플레이어 대쉬 구현

[Header("Dash Info")]
[SerializeField]
private float dashSpeed;
[SerializeField]
private float dashDuration;
// [SerializeField]
private float dashTime;
[SerializeField]
private float dashCooldown;
// [SerializeField]
private float dashCooldownTimer;

private void MovePlayer()
{
    xInput = Input.GetAxisRaw("Horizontal");

    HandleDash();

    if (dashTime > 0)
    {
        rb.linearVelocity = new Vector2(xInput * dashSpeed, 0);
    }
    else
    {
        rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocityY);
    }
}

private void HandleDash()
{
    dashTime -= Time.deltaTime;
    dashCooldownTimer -= Time.deltaTime;

    if (Input.GetKeyDown(KeyCode.LeftShift) && dashCooldownTimer < 0)
    {
        dashCooldownTimer = dashCooldown;
        dashTime = dashDuration;
    }
}

private void HanldeAnimator()
{
    animator.SetBool("isDashing", dashTime > 0);
}

공격 콤보 구현

[Header("Attack Info")]
[SerializeField]
private float comboTime = 0.3f;
private float comboTimeCounter;
private bool isAttacking;
private int comboCounter;

private void Attack()
{
    comboTimeCounter -= Time.deltaTime;

    if (Input.GetKeyDown(KeyCode.Mouse0))
    {
        isAttacking = true;
        comboTimeCounter = comboTime;
    }
}

public void FinishAttack()
{
    isAttacking = false;

    comboCounter++;

    if (comboCounter > 2)
    {
        comboCounter = 0;
    }

    if (comboTimeCounter < 0)
    {
        comboCounter = 0;
    }
}

📝 과제

캐릭터 리소스 변경해보기

https://github.com/yh97yhyh/likelion-unity-study/tree/main/ShadowDashAssignment

 

likelion-unity-study/ShadowDashAssignment at main · yh97yhyh/likelion-unity-study

Contribute to yh97yhyh/likelion-unity-study development by creating an account on GitHub.

github.com

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함