using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimatorController : MonoBehaviour { public Animator[] animators; public Transform target; public float speed = 1f; // Use this for initialization void Start() { for (int i = 0; i < animators.Length; i++) { animators[i].SetFloat("Walking Speed", speed); } } // Update is called once per frame void Update() { float distanceFromTarget = Vector3.Distance(animators[2].transform.position, target.position); if (distanceFromTarget < 15) { float speed = (distanceFromTarget / 15) / 1; for (int i = 0; i < animators.Length; i++) { animators[i].SetFloat("Walking Speed", speed); } } if(distanceFromTarget < 1) { for(int i = 0; i < animators.Length; i++) { animators[i].SetFloat("Walking Speed", 0); } } } } This part of the slowdown is working fine:
float distanceFromTarget = Vector3.Distance(animators[2].transform.position, target.position); if (distanceFromTarget < 15) { float speed = (distanceFromTarget / 15) / 1; for (int i = 0; i < animators.Length; i++) { animators[i].SetFloat("Walking Speed", speed); } } I tried to add this part to make the characters stop:
if(distanceFromTarget < 1) { for(int i = 0; i < animators.Length; i++) { animators[i].SetFloat("Walking Speed", 0); } } But they never stop. They are slowing down then continue walking slow and then the speed moving up again once they are getting away from the target.
I want them to slowdown when the distance is 15 and less and once animators[2] distance is 1 from target stop.
Screenshot of the Animator: The two soldiers have the same animator controller the other character have it's own controller all of them have the same states and parameters and same settings:

