// Update is called once per frame void Update() { if (Vector3ExtraTool.DistanceIgnoreYAxis(target.position, transform.position) < 5f && !isTriggerred) { isTriggerred = true; for (int index = 0; index < createEnemyNumber; index++) { EnemyPool.Instance.CreateEnemy(transform); } } }
IEnumerator AttackLogic() { while (true) { //超出攻击区域 if (Vector3ExtraTool.DistanceIgnoreYAxis(transform.position, _attackPlayer.position) > _attackDis) { ani.SetInteger("ToPhyAttack", 0); yield break; } //Debug.Log(ani.GetCurrentAnimatorStateInfo(0).normalizedTime); //if (ani.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f) // ani.SetInteger("ToPhyAttack", Random.Range(1, 4)); yield return(new WaitForEndOfFrame()); } }
IEnumerator MoveLogic() { while (true) { //抵达跟随区域 if (Vector3ExtraTool.DistanceIgnoreYAxis(transform.position, _attackPlayer.position) <= _followDis) { yield return(StartCoroutine(FollowLogic())); } if (Vector3ExtraTool.DistanceIgnoreYAxis(transform.position, targetPosition) <= _errorDis) { ani.SetBool("ToRun", false); targetPosition = RandomPoint() + defaultPosition; yield return(StartCoroutine(ThinkLogic())); } ani.SetBool("ToRun", true); MoveToTargetWayPosition(targetPosition); // 移动到目标点 yield return(new WaitForEndOfFrame()); } }
IEnumerator FollowLogic() { while (true) { if (Vector3ExtraTool.DistanceIgnoreYAxis(transform.position, _attackPlayer.position) > _followDis) { yield break; } //抵达攻击区域 if (Vector3ExtraTool.DistanceIgnoreYAxis(transform.position, _attackPlayer.position) <= _attackDis) { ani.SetBool("ToRun", false); ani.SetInteger("ToPhyAttack", Random.Range(1, 3)); yield return(StartCoroutine(AttackLogic())); } ani.SetBool("ToRun", true); MoveToTargetWayPosition(_attackPlayer.position); // 移动到目标点 yield return(new WaitForEndOfFrame()); } }
public void DoAttack() { isAttack = true; ani.SetBool("ToIdleFight", false); ani.SetInteger("ToPhyAttack", Random.Range(1, 3)); ani.SetBool("ToRun", false); for (int index = 0; index < EnemyPool.Instance.enemyList.Count; index++) { GameObject enemy = EnemyPool.Instance.enemyList[index]; if (Vector3ExtraTool.DistanceIgnoreYAxis(enemy.transform.position, transform.position) > canAttackDis) { continue; } float dot = Vector3.Dot(transform.forward, (enemy.transform.position - transform.position).normalized); if (dot <= Mathf.Cos(Mathf.PI * canAttackFOV / 2 / 180)) //不在攻击区域 { continue; } Debug.Log("DoHurt"); enemy.SendMessage("DoHurt", Random.Range(5, 20), SendMessageOptions.DontRequireReceiver); } }
IEnumerator ThinkLogic() { while (true) { //抵达跟随区域 if (Vector3ExtraTool.DistanceIgnoreYAxis(transform.position, _attackPlayer.position) <= _followDis) { currentTime = 0f; ani.SetBool("ToIdleFight", false); yield break; } ani.SetBool("ToIdleFight", true); currentTime += Time.deltaTime; if (currentTime >= _thinkTime) { currentTime = 0f; ani.SetBool("ToIdleFight", false); yield break; } yield return(new WaitForFixedUpdate()); } }