Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Help with Animations not playing correctly (even at all)

Discussion in 'Animation' started by LockHowl, Sep 8, 2020.

  1. LockHowl


    Jan 6, 2016
    Hi guys,

    I can't seem to get my animations to do what I want them to do despite following many guides. I just can't seem to get it to work so I must be missing something vital.

    The rundown is:
    - I spawn multiple instances of sheep with a common animation controller
    - They move in a flock behaviour, if there is no nearby animal (checked with OverlapSphere), they stay put (and should do an Idle animation)
    - If there is more than one nearby, they run around (and should do Run animation)

    My script for this:
    Code (CSharp):
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEditor.Animations;
    6. using UnityEngine;
    8. public class AnimControl : MonoBehaviour
    9. {
    10.     Animator anim;
    12.     void Start()
    13.     {
    14.         anim = GetComponent<Animator>();
    15.     }
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         if (Physics.OverlapSphere(gameObject.transform.position, gameObject.GetComponent<SphereCollider>().radius) != null)
    21.         {
    22.             if (anim.GetBool("Running") != true)
    23.                 anim.SetBool("Running", true);
    24.         }
    25.         else if (anim.GetBool("Running") != false)
    26.                 anim.SetBool("Running", false);
    27.     }
    28. }
    My parameter being "Running" to determine if the animal is Idle or Running. I've checked to see if my animations are functional to my model individually and they are.
    I've set my looper:
    I've assigned my arrows and removed my exit time:

    The problem that I get is that my sheep do the default animation once so the default animation bar progresses to the end and then the animation bar just stays stuck at the end. I've also attached how my animator looks.

    Thanks for listening.

    Attached Files: