public IEnumerator AIChase() { while (currentstate == SOLDIER_STATE.CHASE) { ThisLineSight.Sensitity = LineSight.SightSensitivity.LOOSE; ThisAgent.isStopped = false; ThisAgent.SetDestination(ThisLineSight.LastKnowSighting); while (ThisAgent.pathPending) { yield return(null); } if (ThisAgent.remainingDistance <= ThisAgent.stoppingDistance) { ThisAgent.isStopped = true; if (!ThisLineSight.CanSeeTarget) { CurrenrState = SOLDIER_STATE.PATROL; } else { CurrenrState = SOLDIER_STATE.ATTACK; } yield break; } } yield return(null); }
public override void Die() { base.Die(); if (animator != null) { animator.SetFloat("Speed", 0f); animator.SetFloat("PlayerWalking", 0f); } currentState = SOLDIER_STATE.DYING; Destroy(rigidBody); Destroy(GetComponent <Collider2D>()); }
public IEnumerator AIPatrol() { while (currentstate == SOLDIER_STATE.PATROL) { print("我已经打到你了!" + Random.value); ThisLineSight.Sensitity = LineSight.SightSensitivity.STRICT; ThisAgent.isStopped = false; ThisAgent.SetDestination(PatrolDestination.position); while (ThisAgent.pathPending) { yield return(null); } if (ThisLineSight.CanSeeTarget) { ThisAgent.isStopped = true; CurrenrState = SOLDIER_STATE.CHASE; yield break; } } yield return(null); }
public IEnumerator AIAttack() { while (currentstate == SOLDIER_STATE.ATTACK) { ThisAgent.isStopped = false; ThisAgent.SetDestination(ThisLineSight.LastKnowSighting); while (ThisAgent.pathPending) { yield return(null); } if (ThisAgent.remainingDistance > ThisAgent.stoppingDistance) { CurrenrState = SOLDIER_STATE.CHASE; yield break; } else { } yield return(null); } yield return(null); }
// Use this for initialization void Start() { GameObject[] Destinations = GameObject.FindGameObjectsWithTag("Dest"); PatrolDestination = Destinations[Random.Range(0, Destinations.Length)].GetComponent <Transform>(); CurrenrState = SOLDIER_STATE.PATROL; }