usingSystem.Collections;
usingSystem.Collections.Generic;
usingUnityEngine;
usingUnityEngine.XR;
//usingUnity.XR;//必须引入
publicclassControlObjects:MonoBehaviour
{
privatefloatxSpeed=100.0f;//左右旋转速度
privatefloatx=0.0f;
voidStart()
{
}
//Updateiscalledonceperframe
voidUpdate()
{
//右控制器:移动偏移量
Vector2vecRight2dAxis=Vector2.zero;
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.primary2DAxis,outvecRight2dAxis);
transform.position=newVector3(
transform.position.x+vecRight2dAxis.x*Time.deltaTime,
transform.position.y,
transform.position.z+vecRight2dAxis.y*Time.deltaTime);
//左控制器:旋转偏移量
Vector2vecLeft2dAxis=Vector2.zero;
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).TryGetFeatureValue(CommonUsages.primary2DAxis,outvecLeft2dAxis);
x+=vecLeft2dAxis.x*xSpeed*0.02f;
//欧拉角转化为四元数
Quaternionrotation=Quaternion.Euler(0,x,0);
transform.rotation=rotation;
}
}
如果觉得《unity pico3 c# 脚本 使用手柄摇杆控制移动和旋转》对你有帮助,请点赞、收藏,并留下你的观点哦!