protected override void Update() { //已爆炸跳过 if (m_IsExploded) { return; } //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //旋转 transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World); //检测(存活/死亡) GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster"); foreach (GameObject monsterObject in monsterObjects) { Monster monster = monsterObject.GetComponent <Monster>(); //忽略已死亡的怪物 if (monster.IsDead) { continue; } if (Vector3.Distance(transform.position, monster.transform.position) <= Consts.RangeClosedDistance) { //敌人受伤 monster.Damage(this.Attack); if (monster.Hp <= 0) { Random random = new Random(); GameModel gm = MVC.GetModel <GameModel>(); gm.Gold += Random.Range(5, 15); } //爆炸 Explode(); //退出(重点) break; } } //边间检测 if (!m_IsExploded && !MapRect.Contains(transform.position)) { Explode(); } }
protected override void Update() { //已爆炸无需跟踪 if (m_IsExploded) { return; } //目标检测 if (Target != null) { if (!Target.IsDead) { //计算方向 Direction = (Target.transform.position - transform.position).normalized; } //角度 LookAt(); //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //打中目标 if (Vector3.Distance(transform.position, Target.transform.position) <= Consts.DotClosedDistance) { //敌人受伤 Target.Damage(this.Attack); if (Target.Hp <= 0) { Random random = new Random(); GameModel gm = MVC.GetModel <GameModel>(); gm.Gold += Random.Range(5, 15); } //爆炸 Explode(); } } else { //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //边界检测 if (!m_IsExploded && !MapRect.Contains(transform.position)) { Explode(); } } }
protected override void Update() { //已爆炸跳过 if (m_IsExploded) { return; } //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //旋转 // transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World); //检测(存活/死亡) GameObject[] enemyObjects = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject enemyObject in enemyObjects) { Enemy enemy = enemyObject.GetComponent <Enemy>(); //忽略已死亡的怪物 if (enemy.IsDead) { continue; } if (Vector3.Distance(transform.position, enemy.transform.position) <= Consts.RangeClosedDistance) { //敌人受伤 enemy.Damage(this.Attack); //爆炸 Explode(); //退出(重点) break; } } //边间检测 if (!m_IsExploded && !MapRect.Contains(transform.position)) { return; } //Explode(); }
protected override void Update() { //已爆炸跳过 if (IsExploded) { return; } //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //旋转 transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World); //检测(存活/死亡) GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster"); foreach (GameObject monsterObject in monsterObjects) { Monster monster = monsterObject.GetComponent <Monster>(); //忽略已死亡的怪物 if (monster.IsDead) { continue; } if (Vector3.Distance(transform.position, monster.transform.position) <= 0.7f) { //敌人受伤 monster.Damage((int)Attack); //爆炸 Explode(); //退出(重点) break; } } //边间检测 if (!IsExploded && !MapRect.Contains(transform.position)) { Explode(); } }
protected override void Update() { //已爆炸无需跟踪 if (f_isExploded) { return; } //目标检测 if (Target != null) { if (!Target.IsDead) { //计算方向 Direction = (Target.transform.position - transform.position).normalized; } //角度 LookAt(); //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //打中目标 if (Vector3.Distance(transform.position, Target.transform.position) <= FBConsts.DotClosedDistance) { //敌人受伤 Target.Damage(Attack); //爆炸 Explode(); } } else { //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //边界检测 if (!f_isExploded && !MapRect.Contains(transform.position)) { Explode(); } } }
protected override void Update() { base.Update(); if (IsExploded) { return; } if (_target != null) { if (!_target.IsDead) { _direction = (_target.transform.position - transform.position).normalized; } //角度 LookAt(); //移动 transform.Translate(_direction * Speed * Time.deltaTime, Space.World); //击中 if (Vector3.Distance(_target.transform.position, transform.position) <= 0.1f) { _target.Damage((int)Attack); Explode(); } } else { //移动中,monster被消灭 transform.Translate(_direction * Speed * Time.deltaTime, Space.World); if (!MapRect.Contains(transform.position) && !IsExploded) { Explode(); } } }