using UnityEngine;
using System.Collections;
public class HandelButtonRight : MonoBehaviour
{
#region Value File
[SerializeField]
SteamVR_TrackedObject trackedObj; /// /// 想要移动的物体
/// [SerializeField] Transform moveObj;
//当前位置
float currentPos = 0;
//距离差
float disCurrent = 0;
//Y轴距当前位置
float currentPosY = 0;
//距离差
float disCurrentY = 0;
[Tooltip("设置旋转角度,默认为100")] public float setRotateAngle = 100.0f; [Tooltip("设置上下移动距离,默认为0.5")] public float setMoveDistance = 0.5f;
#endregion
#region MonoMathod
// Use this for initialization
void Start() { }
// Update is called once per frame
void Update() {
currentPos = this.transform.position.x;
currentPosY = this.transform.position.y;
var decive = SteamVR_Controller.Input((int)trackedObj.index);
if (decive.GetPress(SteamVR_Controller.ButtonMask.Trigger))
{ if (disCurrent > 0.001f) { moveObj.Rotate(-Vector3.up * Time.deltaTime * setRotateAngle); } else if (disCurrent == 0) { return; } else if (disCurrent < -0.001f) { moveObj.Rotate(Vector3.up * Time.deltaTime * setRotateAngle); } //---------------------- if (disCurrentY > 0.005f) { moveObj.Translate(Vector3.up * Time.deltaTime * setMoveDistance); } else if (disCurrentY == 0) { return; } else if (disCurrentY < -0.005f) { moveObj.Translate(-Vector3.up * Time.deltaTime * setMoveDistance); } } } void FixedUpdate() { disCurrent = this.transform.position.x - currentPos; disCurrentY = this.transform.position.y - currentPosY; } void Awake() { trackedObj = GetComponent();
}
#endregion
}