Unity_XR控制手部动画
文章目录
- 一、添加左右手部模型
- 1.添加XR Origin
- 2.添加模型
- 二、添加控制手部动画脚本
- 1.查看手部动画
- 2.编写脚本
- 3.添加脚本到有动画的模型上
- 4.设置脚本中的变量
手部模型下载链接
效果展示
一、添加左右手部模型
1.添加XR Origin
2.添加模型
二、添加控制手部动画脚本
1.查看手部动画
2.编写脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;public class AnimateHandController : MonoBehaviour
{public InputActionProperty pinchActionProperty_Select_value;public InputActionProperty gripActionProperty_ActivateValue;private InputAction pinchAction;private InputAction gripAction;private Animator animator;// Start is called before the first frame updatevoid Start(){pinchAction = pinchActionProperty_Select_value.action;gripAction = gripActionProperty_ActivateValue.action;animator = GetComponent<Animator>();}// Update is called once per framevoid Update(){float triggerValue = pinchAction.ReadValue<float>();animator.SetFloat("Trigger", triggerValue);float gripValue = gripAction.ReadValue<float>();animator.SetFloat("Grip",gripValue);}
}
3.添加脚本到有动画的模型上
4.设置脚本中的变量
注意找到对应左右的值拖进去