using System.Collections.Generic; using UnityEditor.Build.Reporting; using UnityEngine; using UnityEngine.XR; using UnityEngine.XR.Interaction.Toolkit;
publicclassPlayBall : MonoBehaviour { public XRController leftController; // Start is called before the first frame update voidStart() {
}
// Update is called once per frame voidUpdate() { Vector2 result; //创建了一个二维向量 var success = leftController.inputDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out result); //检测左手设备摇杆 (第一个参数是他的轴 按键摇杆の位置,第二个是给result赋值 out就是说这个值是通过这个方法里面来给他进行赋值的) // var success 并且会返回一个布尔值 假如调用成功了就true 失败就失败了 if (success) { //成功获取了偏移量就会触发这个函数 var position = transform.position; transform.position = new Vector3(position.x + result.x, position.y, position.z + result.y); //y轴是向上的轴,所以是原来的即可 }