250310 TIL

박소희·2025년 3월 10일

Unity_7기

목록 보기
43/94

즉발 아이템 효과 해제

문제

  • 아이템 효과가 일정 시간 후에 해제 되어야 하는데 해제가 되지 않는다.
IEnumerator ApplyItem(ItemData item)
{
    switch (item.active.type)
    {
        case ActiveType.Speed:
            CharacterManager.Instance.Player.controller.moveSpeed += item.active.value;
            break;
        case ActiveType.Invincible:
            CharacterManager.Instance.Player.condition.invincible = true;
            break;
    }

    yield return new WaitForSeconds(item.active.duration);

    switch (item.active.type)
    {
        case ActiveType.Speed:
            CharacterManager.Instance.Player.controller.moveSpeed -= item.active.value;
            break;
        case ActiveType.Invincible:
            CharacterManager.Instance.Player.condition.invincible = false;
            break;
    }
    
}

해결

  • 아이템을 상호작용하면 아이템이 삭제되어서 다음 코드가 실행이 안된 것이였다..
  • 아이템 실행 코드를 다른 스크립트로 옮겨 해결했다.

플랫폼 발사대

문제

  • 플레이어 위치 조정하고 발사하는 것까지 코루틴으로 만들어놨는데, 발사만 안된다..
IEnumerator LaunchCo(Rigidbody rb, Transform player)
{
    player.position = transform.position;
    rb.isKinematic = true;
    player.SetParent(transform);

    Quaternion targetRotation = Quaternion.Euler(0, 0, angle);

    float elapsedTime = 0f;
    while(elapsedTime < 2f)
    {
        elapsedTime += Time.deltaTime;
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, elapsedTime);
        yield return null;

    }

    yield return new WaitForSeconds(delay);

    rb.isKinematic = false;
    Vector3 launchDirection = transform.up;
    rb.AddForce(launchDirection * launchPower, ForceMode.Impulse);
    Debug.Log(rb.velocity);
    player.SetParent(null);

}

해결

  • isKinematic = false를 했는데도 바로 적용이 안돼서 AddForce가 안됐었다.
  • 위치 고정하는 부분은 없앴다.

문제

  • 발사대에 탄 플레이어가 계속 위로만 발사된다..

해결

  • PlayerController의 FixedUpdate에서 Move() 때문이었다.
  • Move()를 특정 조건에서만 실행되게 바꾸어 해결하였다.

0개의 댓글