6-21. 15조 InGameUI, FallingObstalceObject, MonsterSound

keubung·2024년 12월 24일

1. InGameUI

  • 인게임 ui에 상호작용 텍스트 출력

  • 인벤토리(손에 든 아이템)에 변동이 있을 때마다 적용

  • 엑셀파일 ItemTable의 ActionText 사용

    InGameUI.cs

    private void SetInteractKey(IInteractable interact)
    {
        if(interact == null)
        {
            interactKeyText.text = "";
        }
        else
        {
            interactKeyText.text = "[Shift + right-click]\n: " + interact.ActionText;
        }
    }

    Init()에 함수 연결

    EntityManager.Instance.Player.PlayerInventory.OnHandItemChanged += SetInteractKey;

    PlayerInventory.cs
    - 각 상태에 따라 적용

    public void SetHand()
    -> OnHandItemChanged?.Invoke(item);
    private void DropItem()
    -> OnHandItemChanged?.Invoke(groundItemStack.TryPeek(out InHandItem nextItem) ? nextItem : null);
  • 실행 결과

    • 물건을 들고있지 않을 때 : 아무 글씨도 뜨지 않음.
    • 물건을 들었을 때 : 상호작용 텍스트
    • 물건을 버리거나 동작을 수행했을 때(손에 물건이 X) : 아무 글씨도 뜨지 않음.

2. FallingObstalceObject

  • 역할은 같지만 약간 수정
    if (isFallen)
        return;
    
    rb.isKinematic = false;
    rb.constraints = RigidbodyConstraints.None;
    
    Vector3 forceDirection = forcePosition.right;
    rb.AddForceAtPosition(forceDirection * forceAmount, forcePosition.position, ForceMode.Impulse);
    
    isFallen = true;
    rb.isKinematic = true;

3. MonsterSound

  • 상태에 맞는 사운드 출력
  • 상태가 바뀔 때 isPlaying과 curTime 초기화
    public void PlayHitSound()
    {
        if (!isPlaying)
        {
            isPlaying = true;
            Managers.Sound.SFX3DPlay(hitSound, this.transform);
        }
    }
    
    public void PlayWalkSound()
    {
        curTime += Time.deltaTime;
        if (curTime > maxWalkingTime)
        {
            Managers.Sound.SFX3DPlay(walkSound, this.transform);
            curTime = 0f;
        }
    }
    
    public void OnResetState()
    {
        isPlaying = false;
        curTime = 0f;
    }

+ MonsterFleeing 상태, Stun 상태 -> MonsterFleeing 상태로 통합

profile
김나영(Unity_6기)

0개의 댓글