title: How can I start a transitions between two animations using a bool parameter in my script?
body: <p>I added a transition between Walk and Idle and added a new parameter name Idle type bool. In the transition I set Has Exit Time to false and then in the Conditions I added the Idle parameter set it to false.</p>
  
  <p><a href="https://i.stack.imgur.com/0Encf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Encf.jpg" alt="Transition"></a></p>
  
  <p>But when running the game the transition is working even if the Idle parameter is set to false.</p>
  
  <p>I want that in my script in some specific condition the transition will start between the Walk and Idle.</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class AnimatorController : MonoBehaviour
  {
      public Animator[] animators;
      public Transform target;
      public float speed = 1f;
      public float rotationSpeed;
      public bool slowDown = false;
  
      private bool endRot = false;
      private Vector3 center;
  
      // Use this for initialization
      void Start()
      {
          center = target.GetComponent&lt;Renderer&gt;().bounds.center;
  
          for (int i = 0; i &lt; 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);
  
          for(int i = 0; i &lt; animators.Length; i++)
          {
              animators[2].transform.position = Vector3.MoveTowards(animators[2].transform.position, center, 0);
          }
  
          if (slowDown)
          {
              if (distanceFromTarget &lt; 10)
              {
                  float speed = (distanceFromTarget / 10) / 1;
                  for (int i = 0; i &lt; animators.Length; i++)
                  {
                      animators[i].SetFloat("Walking Speed", speed);
                  }
              }
          }
  
          if (distanceFromTarget &lt; 3.5f)
          {
              for (int i = 0; i &lt; animators.Length; i++)
              {
                  animators[i].SetFloat("Walking Speed", 0);
              }
  
              if (!endRot)
              {
                  Quaternion goalRotation = Quaternion.Euler(0f, 180f, 0f);
                  float angleToGoal = Quaternion.Angle(
                          goalRotation,
                          animators[0].transform.localRotation);
                  float angleThisFrame = Mathf.Min(angleToGoal, rotationSpeed * Time.deltaTime);
  
                  // use axis of Vector3.down to keep angles positive for ease of use
                  animators[0].transform.Rotate(Vector3.up, angleThisFrame);
                  animators[1].transform.Rotate(Vector3.down, angleThisFrame);
  
                  // We end if we rotated the remaining amount.
                  endRot = (angleThisFrame == angleToGoal);
              }
          }
      }
  }
  </code></pre>
  
  <p>I want that instead stop the object here:</p>
  
  <pre><code>if (distanceFromTarget &lt; 3.5f)
              {
                  for (int i = 0; i &lt; animators.Length; i++)
                  {
                      animators[i].SetFloat("Walking Speed", 0);
                  }
  </code></pre>
  
  <p>To slowly smooth change between walking and idle.
  The transition is working fine in the editor but I want it to start only when the distance is less then 3.5 and now when running the game the transition is starting much faster.</p>