- Home /
Need to know when a transition starts in mecanim.
So I'm using a behaviours script and there's onstateenter, onstateupdate and onstateexit. But from my experience none of them gives me the exact point a transition from one animation to the next one starts.
Maybe with Animator.isintransition?
I have no idea and really need help to find out. Please.
Thank you
Answer by YTGameDevDave · Oct 29, 2017 at 05:43 PM
I've solved it by converting the framelength of the animation from 24fps (blender) to 60fps (unity) by comparing fractions, then converting the new framelength to seconds and then using time.deltatime to know when the animation stops + adding extra seconds for the transition duration. Now I have the exact point when the transition starts and when it ends.
this is a better way
public class InverseTransitionRotation : State$$anonymous$$achineBehaviour {
int li;
float t;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
t = 0;
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
li = layerIndex;
t += Time.deltaTime;
//in this if-statement insert your input for the first transition's 'transition duration'
if (t >= 0.1f) {
if (animator.IsInTransition (li) == true) {
DoSomething(); //code here
}
}
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
t = 0;
}
}
Your answer
Follow this Question
Related Questions
Mecanim - How to use "Exit Time" for a state that uses negative speed (anim playing backwards)? 2 Answers
Make mecanim transition after a delay in Unity3D 0 Answers
Combining two animations to be one 0 Answers
What are those white curves in the animation transition panel - And can I read it in script? 0 Answers