/// <summary> /// 攻击状态构造函数 /// </summary> /// <param name="host"></param> public GeneralWalkState(GeneralSoldier host) : base(host) { //取得士兵和动画 _host = host; _navmeshAgent = _host.GetComponent<NavMeshAgent>(); }
/// <summary> /// 攻击状态构造函数 /// </summary> /// <param name="host"></param> public GeneralAttackState(GeneralSoldier host) : base(host) { //取得士兵和动画 soldier = host; animator = soldier.GetComponent <Animator>(); }
/// <summary> /// 攻击状态构造函数 /// </summary> /// <param name="host"></param> public GeneralWalkState(GeneralSoldier host) : base(host) { //取得士兵和动画 _host = host; _navmeshAgent = _host.GetComponent <NavMeshAgent>(); }
/// <summary> /// 攻击状态构造函数 /// </summary> /// <param name="host"></param> public GeneralHurtState(GeneralSoldier host) : base(host) { //取得士兵和动画 soldier = host; animator = soldier.GetComponent<Animator>(); }
/// <summary> /// 初始化 /// </summary> public override void init() { _target = null; //播放移动动作 _host.GetComponent <Animator>().Play("run01"); _host.walkStop(); _host.walkEnable(); }
/// <summary> /// 每帧的更新 /// </summary> public override void update() { //如果死亡 if (_deadDelay <= 0) { _host.notifyEvent(this, DEAD_COMPLETE_EVENT, null); return; } //计时 _deadDelay--; //播放死亡动画 _host.GetComponent <Animator>().Play("die01"); }
/// <summary> /// 每帧的更新 /// </summary> public override void update() { if (_host == null) { return; } //播放移动动作 _host.GetComponent <Animator>().Play("run01"); //面向敌人 _host.gameObject.transform.LookAt(_host._data.AttackTarget.gameObject.transform); //向目标靠近,靠近速度是自身的移动速度 _host.gameObject.transform.Translate(Vector3.forward * Time.deltaTime * _host._data.MoveSpeed); //如果进入攻击范围,靠近行为结束 if (Vector3.Distance(_host.transform.position, _host._data.AttackTarget.transform.position) <= _host._data.AttckDistance) { //发靠近行为结束消息 notifyEvent(MOVE_COMPLETE_EVENT); } }
/// <summary> /// 每帧的更新 /// </summary> public override void update() { _host.GetComponent <Animator>().Play("win01"); }
/// <summary> /// 初始化 /// </summary> public override void init() { //运行待机动画 _host.GetComponent <Animator>().Play("idle01"); }