/// <summary> /// 攻击按钮事件 /// </summary> public void AttackBtnUp() { float timeLimit; if (Player.Instance.isAttackQuick) { timeLimit = Const.attackTimeUnitQ; } else { timeLimit = Const.attackTimeUnit; } if (attackTime > timeLimit) { if (Player.Instance.HasEnemy()) { MonsterMeg attackMos = Player.Instance.GetAttackMonster(); Player.Instance.go.transform.LookAt(attackMos.pos); //arrowModel.transform.LookAt(attackMos.pos); } arrowModel.transform.rotation = Player.Instance.go.transform.rotation; Player.Instance.Attack(); attackTime = 0; } AttackRange.SetActive(false); }
/// <summary> /// 删除可攻击敌人 /// </summary> /// <param name="meg"></param> private void RemoveMonster(object meg) { MonsterMeg go = (MonsterMeg)meg; for (int i = 0; i < monsterList.Count; i++) { if (monsterList[i] == go) { monsterList.Remove(go); } } }
/// <summary> /// 增加可攻击敌人 /// </summary> /// <param name="meg"></param> private void AddMonster(object meg) { MonsterMeg go = (MonsterMeg)meg; foreach (var i in monsterList) { if (i == go) { return; } } monsterList.Add(go); }
/// <summary> /// 返回优先攻击的敌人 /// </summary> /// <returns></returns> public MonsterMeg GetAttackMonster() { if (monsterList.Count == 0) { Debug.Log("NO Monster"); return(null); } MonsterMeg attackMonster = monsterList[0]; float minDis = monsterList[0].distance; for (int i = 1; i < monsterList.Count; i++) { if (monsterList[i].distance < minDis) { attackMonster = monsterList[i]; } } return(attackMonster); }
// Use this for initialization public void Init(bool isTrack) { isAttack = false; hasAdd = false; agent = this.GetComponent <NavMeshAgent>(); anim = this.GetComponent <Animator>(); target = GameObject.Find("Player"); isTrackTarget = isTrack; self = new MonsterMeg(this.gameObject); canMove = true; fullBlood = blood; isBlood = false; StartMove(); //if (move != null) //{ // StopCoroutine(move); //} //move = SetMove(); //StartCoroutine(move); }