| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using static Spine.Unity.Examples.SpineboyFootplanter;
- using TMPro;
- public class Tower : Character
- {
- [Header("ËþÐÅÏ¢")]
- public string name;
- public bool isLockSoul;
- public float height = 8;
- private void Awake()
- {
- TowerMap.myTowers.Add(gameObject);
- Init();
- //attackController.ChooseAttack(0);
- attackController.curAttackMethod = attackController.attackMethod_march[0];
- }
- public bool GetAttack()
- {
- if (targetCharacter != null)
- {
- return true;
- }
- return false;
- }
- public void SearchTarget()
- {
- targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, true, attackController.curAttackMethod.searchMode);
- }
- public void Attack_March()
- {
- GameObject bulletObj = PoolManager.Instantiate(attackController.curAttackMethod.bulletPrefab);
- attackController.attackTime = attackController.attackKeys[0].totalTime;
- Bullet bullet = bulletObj.GetComponent<Bullet>();
- AttackInfo attackInfo = attackController.curAttackMethod.attackInfo;
- Vector3 attackDir = attackInfo.attackDir.normalized;
- if (bodyTrans.localScale.x < 0)
- {
- attackDir.x = -attackDir.x;
- }
- bullet.BeShoot(this, attackController.curAttackMethod.shootPos[0].position, attackDir, attackController.curAttackMethod.shootTrack,
- attackController.curAttackMethod.shootAlwaysTrack, attackTarget ? attackTarget : null);
- }
- public override void OnState()
- {
- base.OnState();
- SearchTarget();
- attackController.attackTime -= Time.deltaTime;
- dieKeepTime -= Time.deltaTime;
- bool isAttack = GetAttack();
- switch (state)
- {
- case CharacterState.Idle:
- if (isAttack)
- {
- ChangeState(CharacterState.Attack);
- break;
- }
- break;
- case CharacterState.Attack:
- if (attackController.attackTime <= 0)
- {
- ChangeState(CharacterState.Idle);
- break;
- }
- break;
- case CharacterState.Die:
- if (dieKeepTime <= 0)
- {
- gameObject.SetActive(false);
- break;
- }
- break;
- default:
- break;
- }
- }
- public override void ChangeState(CharacterState newState)
- {
- switch (state)
- {
- case CharacterState.Idle:
- break;
- case CharacterState.Attack:
- attackTarget = null;
- break;
- case CharacterState.Die:
- isDie = false;
- break;
- default:
- break;
- }
- CharacterState oldState = state;
- state = newState;
- switch (newState)
- {
- case CharacterState.Idle:
- rb.velocity = Vector3.zero;
- break;
- case CharacterState.Attack:
- attackTarget = targetCharacter;
- Attack_March();
- break;
- case CharacterState.Die:
- if (isLockSoul)
- {
- GetComponentInChildren<LockSoul>().ReleaseAllSouls();
- }
- isDie = true;
- dieKeepTime = totalDieKeepTime;
- TowerMap.myTowers.Remove(gameObject);
- break;
- default:
- break;
- }
- }
- public override void BeHit(int damage)
- {
- base.BeHit(damage);
- }
- public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
- {
- base.BeHit(attackMethod.attackInfo.damage);
- }
- }
|