/// <summary> /// Raises the state enter event. /// </summary> /// <param name="previousState">Previous state.</param> /// <param name="newState">New state.</param> public override void OnStateEnter(AiState previousState, AiState newState) { if (path == null) { // If I have no path - try to find it path = FindObjectOfType <Pathway>(); Debug.Assert(path, "Have no path"); } if (destination == null) { // Get next waypoint from my path destination = path.GetNearestWaypoint(transform.position); } // Set destination for navigation agent aiBehavior.navAgent.destination = destination.transform.position; // Start moving aiBehavior.navAgent.move = true; aiBehavior.navAgent.turn = true; // If unit has animator if (anim != null && anim.runtimeAnimatorController != null) { // Search for clip foreach (AnimationClip clip in anim.runtimeAnimatorController.animationClips) { if (clip.name == "Move") { // Play animation anim.SetTrigger("move"); break; } } } }
/// <summary> /// Raises the state enter event. /// </summary> /// <param name="previousState">Previous state.</param> /// <param name="newState">New state.</param> public void OnStateEnter(string previousState, string newState) { if (path == null) { // If I have no path - try to find it path = FindObjectOfType <Pathway>(); Debug.Assert(path, "Have no path"); } if (destination == null) { // Get next waypoint from my path destination = path.GetNearestWaypoint(transform.position); } // Set destination for navigation agent navAgent.Destination = destination.transform.position; if (anim != null) { // Start moving navAgent.Move = true; // Play animation anim.Play(); } }
/// <summary> /// Raises the state enter event. /// </summary> /// <param name="previousState">Previous state.</param> /// <param name="newState">New state.</param> public override void OnStateEnter(AiState previousState, AiState newState) { if (path == null) { // If I have no path - try to find it path = FindObjectOfType <Pathway>(); Debug.Assert(path, "Have no path"); } if (destination == null) { // Get next waypoint from my path destination = path.GetNearestWaypoint(transform.position); } // Set destination for navigation agent navAgent.destination = destination.transform.position; // Start moving navAgent.move = true; navAgent.turn = true; if (anim != null) { // Play animation anim.SetTrigger("move"); } }