using System.Collections.Generic; using UnityEngine; public class UnitCtrl : MonoBehaviour { public UnitInfo unit; public Animator anim; public GameObject defensObj; public Sprite unitSprite; bool isHomeAttack; public BoxCollider2D[] components; public int tableIndex; List enemyUnits; public bool isEnemy; float delay; bool _isDie = false; public bool isDie { get { return _isDie; } } public void DataSet(int tableIndex) { //À̰÷Àº ListÀ¯´Ö¿¡°Ô ¼¼ÆÃµÊ this.tableIndex = tableIndex; unit.UnitSet(Statics.excelDatas.unitData[tableIndex]); } public void UnitBonusSet(bool isEnemy, int unitLevel) { //À̰÷Àº »ý¼ºµÈ À¯´Ö¿¡°Ô ¼¼ÆÃµÊ this.isEnemy = isEnemy; unit.UnitSet(Statics.excelDatas.unitData[tableIndex]); if (!isEnemy)//¾Æ±º À¯´Ö¿¡°Ô¸¸ ¼¼ÆÃÀÌ µÇ¾î¾ßÇÔ unit.DeckUnitInfoSet(); unit.UnitBonusSet(new UnitBonus(unitLevel, new int[0], 0, 0)); } private void Awake() { enemyUnits = new List(); isHomeAttack = false; delay = 0; _isDie = false; } private void Start() { if (isEnemy) { defensObj.tag = "enemy"; transform.localScale = Vector3.one; } else { transform.localScale = new Vector3(-1, 1, 1); defensObj.tag = "player"; } } private void Update() { if (PlayCtrl.Instance.isEndGame || _isDie || PlayCtrl.Instance.isStop) return; delay -= Time.deltaTime; if (delay > 0) return; if (enemyUnits.Count != 0 || isHomeAttack) { anim.SetBool("isMove", false); if (enemyUnits.Count == 0) { anim.SetTrigger("attack"); if (isEnemy) { PlayCtrl.Instance.player.campHp -= unit.attack; if(PlayCtrl.Instance.player.campHp <= 0) { Debug.Log("ÆÐ¹è!"); PlayCtrl.Instance.isEndGame = true; } } else { PlayCtrl.Instance.enemy.campHp -= unit.attack; if (PlayCtrl.Instance.enemy.campHp <= 0) { Debug.Log("½Â¸®!"); PlayCtrl.Instance.isEndGame = true; } } delay = unit.attackSpeed; } else { if (enemyUnits[0] != null && !enemyUnits[0].isDie) { anim.SetTrigger("attack"); enemyUnits[0].Attack(unit.attack); delay = unit.attackSpeed; } else { enemyUnits.RemoveAt(0); } } } else { anim.SetBool("isMove", true); transform.position += Vector3.left * unit.moveSpeed * Time.deltaTime * (isEnemy ? 1 : -1); } } private void OnTriggerEnter2D(Collider2D collision) { if (isEnemy) { if (collision.gameObject.CompareTag("player")) { enemyUnits.Add(collision.gameObject.GetComponentInParent()); } if (collision.gameObject.CompareTag("player_home")) { isHomeAttack = true; } } else { if (collision.gameObject.CompareTag("enemy")) { enemyUnits.Add(collision.gameObject.GetComponentInParent()); } if (collision.gameObject.CompareTag("enemy_home")) { isHomeAttack = true; } } } /// /// °ø°ÝÀ» ¹Þ¾ÒÀ»¶§ È£ÃâµÇ°Ô ¸¸µé±â /// /// °ø°Ý ´ë¹ÌÁö public void Attack(int dmg) { if(unit.defense > dmg) { dmg = unit.defense + 100; } unit.hp -= (dmg - unit.defense); if(unit.hp <= 0) { //Àӽ÷Π»èÁ¦ÇÏ°Ô Ã³¸® ÃßÈÄ ÀçȰ¿ë ÇÒ¼ö ÀÖ°Ô Ã³¸®ÇÒ°Í anim.SetBool("isDie", true); components[0].enabled = false; components[1].enabled = false; _isDie = true; Destroy(gameObject, 1.0f); } } } // ¸®Áöµå, ÄݶóÀÌ´õ À§Ä¡ º¯°æ Unit > oder // oder ÄݶóÀÌ´õ Æ®¸®°Å üũ // µðÆæ½º ¿ÀºêÁ§Æ® Á»´õ »óÀ§·Î À§Ä¡º¯°æ