回到
要让代码控制IK,需要先在Animator中打开IK pass
然后,和IK相关的代码需要放到相应的函数中去:
void OnAnimatorIK(){ Debug.Log("OnAnimatorIK");}
而如果是StateMachineBehaviour,IK操控的代码是在:
public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex){ base.OnStateIK(animator, stateInfo, layerIndex); Debug.Log("OnStateIK");}
测试脚本:
using UnityEngine;using System.Collections;public class IKTest : MonoBehaviour{ public Animator animator; public Transform ikTarget; void OnAnimatorIK() { animator.SetIKPosition(AvatarIKGoal.LeftFoot, ikTarget.position); animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, 1); }}