How To Check Current Animation By Name Unity
When creating an action game or a boxing game, you may want to link a key input to an animation. All animation need transition from anywhere. If each state were connected with all others, Animator should become hard to see. In such instance you can utilize "Whatever Land" of Animator.
Surround: Unity 2018.iv.6f
- How to use Animator "Whatever State".
- The way for simple activity game.
- Take measure for continuous inputs as combat game.
Any State
A state linked to "Any Country" tin can transition from all states.
Only if it's merely linked by "make transition", same animation is chosen many times. Information technology demand uncheck "Can Transition To Self". This parameter is on a cursor of transition.
Call an animation at a primal input
The state isn't called many times just at the end of animation a model just stand. To chage it to a default land yous may link each land to "Exit", then the state is infinitely called once again.
If information technology desire to alter the "Stay" animation, a parameter of Animator demand to be initialized. You change the parameter to "Stay" value later switching a land.
using UnityEngine; using System.Collections; //Need this for coroutine. public grade AnimationManager : MonoBehaviour{ //Set a model's "Animation Controller" on Inspecter. [SerializeField] Animator animator; //Call this method at an inputing key. public void PlayAnimation(int state) { //Create "Command" in Parameters and change each animation by its value. animator.SetInteger("Control", state); StartCoroutine(InitializeParameter()); } IEnumerator InitializeParameter(){ //Need a flame for switching animation. //Without this the above method tin't switch a state. yield return null; animator.SetInteger("Control", 0); } }
Finish coroutine when an input is continuous
If a project is simple action game, the in a higher place code take naught trouble. Notwithstanding, about an intense typing similar boxing game this lawmaking does not work well. If information technology's invoked continuously, a follow input is overwrote by the previous one'due south coroutine. So, it need the process for stopping the coroutine or a input.
using UnityEngine; using Arrangement.Collections; public course AnimationManager : MonoBehaviour{ [SerializeField] Animator animator; bool isContinuous; //Call this method at an inputing key. public void PlayAnimation(int state) { if(isContinuous){ //The way to overwrite the input by new one. StopCoroutine("InitializeParameter"); animator.SetInteger("Command", 0); //The way to stop input. //return; } isContinuous = true; animator.SetInteger("Command", land); //Need to call coroutine by cord for stopping this. //Or the coroutine add IEnumerator variable and telephone call the process by it. //The method way(similar Thirty()) creates new coroutine every time it's invoked. StartCoroutine("InitializeParameter"); } IEnumerator InitializeParameter(){ //Demand a flame for switching animation. //Without this the to a higher place method can't switch a land. yield return null; animator.SetInteger("Command", 0); //Switch the flag after this process has finished. isCoutinuous = false; } }
*Haw to stop coroutine.
References
Source: https://blog.skeyll.net/animator_anystate
Posted by: proctortweat1979.blogspot.com
0 Response to "How To Check Current Animation By Name Unity"
Post a Comment