Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. LockHowl

    LockHowl

    Joined:
    Jan 6, 2016
    Posts:
    2
    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):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEditor.Animations;
    6. using UnityEngine;
    7.  
    8. public class AnimControl : MonoBehaviour
    9. {
    10.     Animator anim;
    11.  
    12.     void Start()
    13.     {
    14.         anim = GetComponent<Animator>();
    15.     }
    16.  
    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. }
    29.  
    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:
    Untitled.png
    I've assigned my arrows and removed my exit time:
    Untitled.png

    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: