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("設(shè)置旋轉(zhuǎn)角度,默認為100")]? ? public float setRotateAngle = 100.0f;? ? [Tooltip("設(shè)置上下移動距離,默認為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
}