Stratasys-450mc-VR/Assets/Scripts/RotateTarget.cs

35 lines
975 B
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.XR.Content.Interaction;
public class RotateTarget : MonoBehaviour
{
[SerializeField] private Transform target;
[SerializeField] private float speed = 10f;
[Range(0f, 1f)]
[SerializeField] private float inputValue = 0f;
[Range(-1f, 1f)]
[SerializeField, ReadOnly] private float direction = 0f;
[SerializeField] private bool invertDirection = false;
private void Update()
{
if (target == null) return;
RemapDirection();
target.RotateAround(target.position, target.up, speed * direction * Time.deltaTime);
}
private void RemapDirection(float min = -1f, float max = 1f)
{
direction = Mathf.Lerp(min, max, inputValue);
direction *= invertDirection ? -1f : 1f;
}
public void SetDirectionValue(float value) => inputValue = value;
}