void Update() { isPathDone = seeker.IsDone(); Vector3 dirToTarget = player.transform.position - transform.position; float angle = Vector3.SignedAngle(dirToTarget, transform.forward, Vector3.up); //if (enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0) //{ if (currentAction == Action.Attack && isPathDone) { seeker.GetCurrentPath().Error(); seeker.StartPath(transform.position, player.transform.position, OnPathComplete); playWalk(angle); } if (currentPath != null && !PathUtilities.IsPathPossible(currentPath.path)) { richAI.SearchPath(); Debug.Log("get back here!"); } if (!richAI.pathPending && richAI.reachedEndOfPath && isPathDone) { playIdle(angle); if (!isCoroutineRunning) { if (currentAction == Action.Seeking) { StartCoroutine(seekWait(angle)); isCoroutineRunning = true; } else if (currentAction == Action.Patrolling) { if (points[(int)nfmod(destPoint - 1, points.Length)].CompareTag("Finish")) { alerted = true; currentAction = Action.Seeking; } else { StartCoroutine(patrollWait(angle)); isCoroutineRunning = true; } } } } else { playWalk(angle); } //} //else //{ // nav.enabled = false; //} }
/// <summary> /// 自动移动 /// </summary> /// <param name="position">目的地</param> public void SetDestination(Vector3 targetPosition) { aiPath.acceleration = float.MaxValue; aiPath.destination = targetPosition; aiPath.SearchPath(); aiPath.onSearchPath = () => { aiPath.canMove = true; }; }