In the image above I am trying to make the meter hand rotate around the meter between the “0” position and the “16” position, without passing through the red zone. Problem is that if I was to click on the “16” button, the meter would move from the “0” position to the “16” position by passing through the red zone… how can I stop this from happening?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeterRotate : MonoBehaviour
{
public float turningRate;
private Quaternion _targetRotation = Quaternion.identity;
public Vector3 initialPosition;
public Vector3 targetRotation;
public Transform target;
public int targetRotate;
/* Need to work out how to handle rotating meter not using the shortest
* distance*/
// Start is called before the first frame update
void Start()
{
// ensures the meter/switch is displayed in the 'off' position on load
SetBlendedEulerAngles(initialPosition);
}
// Update is called once per frame
void Update()
{
var step = turningRate * Time.deltaTime;
// this rotates the meter, but always takes the quickest route
transform.rotation = Quaternion.RotateTowards(transform.rotation,
_targetRotation, step);
}
public void SetBlendedEulerAngles(Vector3 angles)
{
_targetRotation = Quaternion.Euler(angles);
}
}