ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [유니티] 플레이어 능력치 버프/ui표현
    쾌락없는 책임 (공부)/Unity 2020. 12. 1. 22:10
    반응형
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class slotItemExample : MonoBehaviour
    {
        public float buffTime = 10f;    //버프가 지속되는 시간
        float curTime;
    
    
        public Image icon;
        void Start(){
    
        }
        void Awake(){
            icon = GetComponent<Image>();
            icon.fillAmount = 1;
            curTime = buffTime;
        }
        void Update()
        {
            if(Input.inputString == (transform.parent.GetComponent<Slot>().num + 1).ToString()){
                // use item
                Debug.Log("You used item");
                playerAttack.coolTime = playerAttack.coolTime/2.0f;
                StartCoroutine(BuffSystem());
            }
        }
        WaitForSeconds waitTime = new WaitForSeconds(0.1f);
        IEnumerator BuffSystem() {
            while (curTime > 0) {
                curTime -= 0.1f;
                icon.fillAmount = curTime/buffTime;
                yield return waitTime;
            }
            Debug.Log("버프 끝");
            playerAttack.coolTime = playerAttack.coolTime*2.0f;
            Destroy(this.gameObject);    
            
        }
    
        
    
    }
    

    <퀵슬롯 구현>

     퀵슬롯은 아래 영상을 보고 구현했습니다

     

    <핵심>

     나머지 기능들은 영상에 있어 아이템 사용하는 인벤토리용으로는 좋았습니다. 그런데 버프용 아이템을 사용하는 용도로는 ui 표현이 부족해 사용자가 효과가 언제 끝날지 알 수 없었습니다. 때문에 ui 이미지 안에 있는 Image.fillAmount를 사용해서 버프가 지속되는 시간을 표현하기로 했습니다.

     fillAmount를 사용하면 ui에 사용한 이미지가 시계방향으로 줄어들게 되는데 지나가는 시간으 코루틴을 사용해 측정했습니다.

     

    <알아볼 점>

     유니티에 Time.deltaTime를 사용해 시간을 측정하는걸로 아는데 그걸 이용할 수는 없는지

    반응형

    댓글

Designed by Tistory.