Help:
i use animator.crossfade to play animation dynamiclly, but, very occasional, the animation stuck at one frame.
unless the object reload , or the animation re play …
someone has any ideas? help…
Help:
i use animator.crossfade to play animation dynamiclly, but, very occasional, the animation stuck at one frame.
unless the object reload , or the animation re play …
someone has any ideas? help…
Hey,
If you call a transition with crossfade while already in that transition then it will freeze.
What I do is check that we’re not already in, or going to a state before starting the crossfade.
Example:
using UnityEngine;
public class CrossFade : MonoBehaviour
{
Animator anim;
void Awake()
{
anim = GetComponent<Animator>();
}
void Update()
{
if (!anim.GetNextAnimatorStateInfo(0).IsName("StateName") && !anim.GetCurrentAnimatorStateInfo(0).IsName("StateName"))
{
anim.CrossFade("StateName", 0.2f);
// OR:
anim.CrossFadeInFixedTime("StateName", 0.2f);
}
}
}
I don’t think you need to check the current state, but I put it there anyway just to be safe. The ! means == false.
If you have any questions, let me know.
thanks,I’ll check my code right away!