using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DungenMainTest : MonoBehaviour
{
[SerializeField]
private UIDungeonDirectorTest uiDungeonDirectorTest;
[SerializeField]
private PlayerShell player;
void Start()
{
var joystickDirector = this.uiDungeonDirectorTest.uiJoysticDirector;
for (int i = 0; i < joystickDirector.joystickSkillDir.Length; i++)
{
int idx = i;
joystickDirector.joystickSkillDir[idx].shootSkill += () =>
{
joystickDirector.UICoolTimeSkills[idx].GetComponent<UICoolTime>().
Init(this.player.gunShell.currentGun.gunData.skillCoolTime[idx]);
};
joystickDirector.btnSkills[idx].onClick.AddListener(() =>
{
joystickDirector.UICoolTimeSkills[idx].GetComponent<UICoolTime>().
Init(this.player.gunShell.currentGun.gunData.skillCoolTime[idx]);
});
}
joystickDirector.btnDash.onClick.AddListener(() =>
{
float dashCoolTime = 2.1f - PlayerStats.instance.dashRecoverCharacteristic * 0.2f;
joystickDirector.UICoolTimeDash.GetComponent<UICoolTime>().Init(dashCoolTime);
});
}
private void OnEnable()
{
EventDispatcher.Instance.AddListener<int>(EventDispatcher.EventName.PlayerExpUp, OnPlayerExpUp);
}
private void OnDisable()
{
EventDispatcher.Instance.RemoveListener<int>(EventDispatcher.EventName.PlayerExpUp, OnPlayerExpUp);
}
public void OnPlayerExpUp(int monsterExp)
{
if (PlayerStats.instance.gunLevel < 30)
{
PlayerStats.instance.exp += monsterExp;
if (PlayerStats.instance.exp >= 100)
{
PlayerStats.instance.exp = 0;
PlayerStats.instance.gunLevel++;
this.uiDungeonDirectorTest.uiGunCharacteristicChoice.Init();
this.player.gunShell.SetGun();
if (PlayerStats.instance.gunLevel == 10)
this.uiDungeonDirectorTest.uiJoysticDirector.UICoolTimeSkills[1].gameObject.SetActive(false);
if (PlayerStats.instance.gunLevel == 20)
this.uiDungeonDirectorTest.uiJoysticDirector.UICoolTimeSkills[2].gameObject.SetActive(false);
}
}
else PlayerStats.instance.exp = 100;
this.uiDungeonDirectorTest.sliderExp.value = PlayerStats.instance.exp;
this.uiDungeonDirectorTest.txtExp.text = string.Format("{0}/100)", PlayerStats.instance.exp);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UICoolTime : MonoBehaviour
{
[System.NonSerialized]
public float coolTime;
private float maxCoolTime;
private Image img;
private bool isCoolTime;
public void Init(float coolTime)
{
this.img = this.GetComponent<Image>();
this.gameObject.SetActive(true);
this.coolTime = coolTime;
this.maxCoolTime = coolTime;
this.isCoolTime = true;
}
void Update()
{
if (this.isCoolTime)
{
this.coolTime -= Time.deltaTime;
this.img.fillAmount = this.coolTime / this.maxCoolTime;
if (this.coolTime <= 0)
{
this.gameObject.SetActive(false);
}
}
}
}
스킬 버튼 UI를 가려 레이캐스트 터치가 불가능하게 만드는 방법으로 쿨타임을 구현하였습니다. 또한 해당 스킬들은 각각 총기 숙련도에 따라 해금되도록 구현하였습니다.
'Unity2D' 카테고리의 다른 글
Unity) [유니티 2D] 공격 스킬 효과 자연스럽게 수정 (0) | 2023.04.24 |
---|---|
Unity) [유니티 2D] 경험치 획득, 레벨업 기능 구현 (0) | 2023.04.24 |
Unity) [UGUI] UI 파티클 반딧불 효과 구현 (0) | 2023.04.22 |
Unity) [유니티 2D] 패턴을 가진 몬스터 구현 (0) | 2023.04.22 |
Unity) [데이터 구조] 씬 전환 구조 잡기 (0) | 2023.04.20 |