Search Unity

How do I check the value of an object's animation name in an 'if' statement?

Discussion in 'Animation' started by BSL_Games, Jan 14, 2020.

  1. BSL_Games

    BSL_Games

    Joined:
    Dec 6, 2019
    Posts:
    1
    Code (CSharp):
    1.                 if (gameObject.GetCurrentAnimatorStateInfo(0).IsName("Walk Left")) {
    2.                     // Check if animation is walking left, so that left idle animation can play
    3.                 }
    4.                 if (gameObject.GetCurrentAnimatorStateInfo(0).IsName("Walk Right")) {
    5.                     // Check if animation is walking right, so that right idle animation can play
    6.                 }
    7.                 if (gameObject.GetCurrentAnimatorStateInfo(0).IsName("Walk Up")) {
    8.                     // Check if animation is walking up, so that up idle animation can play
    9.                 }
    10.                 if (gameObject.GetCurrentAnimatorStateInfo(0).IsName("Walk Down")) {
    11.                     // Check if animation is walking down, so that left down animation can play
    12.                 }
    I'm trying to use an idle animation per direction.
    I tried this code in the UPDATE void, but it returns
    Type `UnityEngine.GameObject' does not contain a definition for `GetCurrentAnimatorStateInfo' and no extension method `GetCurrentAnimatorStateInfo' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?
    How do I fix this code?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780