I am currently making TPS (Third Person Shooting) at Unity.
I would like to display the key frame I specified when I was armed, but I don't know how to do it.If you move the mouse cursor, your face will follow you.
I'm sorry it's hard to understand.
The Unity version is 5.
It is difficult to get keyframes for animations, but you can calculate them from AnimationClip's frameRate to display them in a specified frame.
public class TestAnimation:MonoBehavior
{
private animator_animator;
void Awake()
{
m_animator=GetComponent<Animator>();
}
public void SetAnimationFrame(inti_frame)
{
varclipInfoList=m_animator.GetCurrentAnimatorClipInfo(0);
varclip=clipInfoList[0].clip;
float time=(float)i_frame/clip.frameRate;
varstateInfo=m_animator.GetCurrentAnimatorStateInfo(0);
variationHash = stateInfo.shortNameHash;
m_animator.Play(animationHash, 0, time);
}
}
However, if you want to point your face or gun in the direction of the mouse cursor, you should calculate the direction on the script and set the rotation of transform instead of animation.
© 2024 OneMinuteCode. All rights reserved.