TestHandPoint.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class TestHandPoint : MonoBehaviour
  6. {
  7. public Transform leftHand;
  8. public Transform rightHand;
  9. private Animator playerAni;
  10. public Animator PlayerAni
  11. {
  12. get
  13. {
  14. if (!playerAni)
  15. {
  16. playerAni = GetComponent<Animator>();
  17. }
  18. return playerAni;
  19. }
  20. }
  21. private void OnAnimatorIK(int layerIndex)
  22. {
  23. if (PlayerAni)
  24. {
  25. PlayerAni.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);
  26. PlayerAni.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f);
  27. //设置左手骨骼的ik目标为胶囊体的坐标和旋转
  28. PlayerAni.SetIKPosition(AvatarIKGoal.RightHand, rightHand.position);
  29. PlayerAni.SetIKRotation(AvatarIKGoal.RightHand, rightHand.rotation);
  30. PlayerAni.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1f);
  31. PlayerAni.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1f);
  32. //设置左手骨骼的ik目标为胶囊体的坐标和旋转
  33. PlayerAni.SetIKPosition(AvatarIKGoal.LeftHand, leftHand.position);
  34. PlayerAni.SetIKRotation(AvatarIKGoal.LeftHand, leftHand.rotation);
  35. }
  36. }
  37. }