using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Monster : MonoBehaviour
{
    public PathFinding pathFinding;
    public AnimationClip deadAnimationClip;

    [System.NonSerialized]
    public int exp = 50;
    public int maxHP = 100;
    [System.NonSerialized]
    public int hp;
    public bool isSkilldDamaged;
    public bool isDead;

    void Start()
    {
        this.hp = this.maxHP;
    }

    public void TakeSkillDamage(int damage, float skillTime)
    {
        this.TakeDamage(damage);
        StartCoroutine(SkillDamagedRoutine(skillTime));
    }

    public IEnumerator SkillDamagedRoutine(float skillTime)
    {
        this.isSkilldDamaged = true;
        yield return new WaitForSeconds(skillTime);
        this.isSkilldDamaged = false;
    }

    public void TakeBulletDamage(int damage)
    {        
        this.TakeDamage(damage);
    }
    
    public void TakeDamage(int damage)
    {
        //Debug.Log(this.hp);
        this.hp -= damage;
        if (this.hp <= 0) isDead = true;
        if (isDead)
        {            
            this.pathFinding.enabled = false;
            this.pathFinding.gameObject.GetComponent<Rigidbody2D>().simulated = false;
            this.pathFinding.gameObject.GetComponent<Collider2D>().enabled = false;
            this.gameObject.GetComponent<Animator>().Play("Dead", -1, 0);
            EventDispatcher.Instance.Dispatch(EventDispatcher.EventName.PlayerExpUp, this.exp);

            StartCoroutine(this.MonsterDeadRoutine());
        }
    }

    IEnumerator MonsterDeadRoutine()
    {
        yield return new WaitForSeconds(this.deadAnimationClip.length);
        this.gameObject.SetActive(false);
    }
}

 몬스터가 죽을 때 새로운 이벤트를 생성 합니다.

 

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);
    }
}

 씬의 Main 스크립트에서 해당 이벤트를 호출 하여 값을 Info에 저장합니다.

 

 

Time.TimeScale을 활용하여 레벨업 후 새로운 특성을 고를 때까지 시간이 멈추도록 하였습니다.

+ Recent posts