int saveRotation = 0;
int currentRotation = 0;
float dragAngle = 0;
int lastSavePoint = 0;
void Update()
{
if (OVRInput.GetDown(OVRInput.Button.PrimaryThumstickUp)
|| OVRInput.GetDown(OVRInput.Button.PrimaryThumstickRight)
|| OVRInput.GetDown(OVRInput.Button.PrimaryThumstickDown)
|| OVRInput.GetDown(OVRInput.Button.PrimaryThumstickLeft))
{
Vector2 pos = Vector2.zero;
dragAngle = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
currentRotation = saveRotation;
}
if (OVRInput.Get(OVRInput.Button.PrimaryThumstickUp)
|| OVRInput.Get(OVRInput.Button.PrimaryThumstickRight)
|| OVRInput.Get(OVRInput.Button.PrimaryThumstickDown)
|| OVRInput.Get(OVRInput.Button.PrimaryThumstickLeft))
{
Vector2 pos = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
int rotation = -(int)((Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg) - dragAngle);
currentRotation = rotation + saveRotation;
transform.localRotation = Quaternion.Euler(0, 0, -currentRotation);
if (currentRotation > lastSavePoint && currentRotation - lastSavePoint == 1)
{
// 角度が上がった時の処理
}
if (lastSavePoint > currentRotation && lastSavePoint - currentRotation == 1)
{
// 角度が下がった時の処理
}
}
if (OVRInput.GetUp(OVRInput.Button.PrimaryThumstickUp)
|| OVRInput.GetUp(OVRInput.Button.PrimaryThumstickRight)
|| OVRInput.GetUp(OVRInput.Button.PrimaryThumstickDown)
|| OVRInput.GetUp(OVRInput.Button.PrimaryThumstickLeft))
{
saveRotation = currentRotation;
transform.localRotation = Quaternion.Euler(0, 0, currentRotation);
}
}