Hello everybody. I am making a mobile car game, I would like to move the needle in the speedometer from 0 position to 180 position; representing the rotation of my phone . All what matter is to rotate the needle when the mobile rotate. Not necessary to represent the exact angle that the mobile rotated.All i need is the visual feedback, when start rotating the mobile clockwise, the needle should rotate clockwise, and vice versa when anticlockwise.
I got z rotation angle for the needle when pointing on 0, then the rotation angle when pointing on maximum value. and made a LERP between them, but the needle does not rotate ,here is the code:-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotationControl : MonoBehaviour
{
static float minAnlge = -43.0F;
static float maxAngle = 222.0F;
static RotationControl thisSpeedo;
// Use this for initialization
void Start()
{
thisSpeedo = this;
}
void Update()
{
//float ang = Mathf.LerpAngle(minAnlge, maxAngle, Time.time);
//thisSpeedo.transform.Rotate (0, 0, ang);
float z = Input.acceleration.x;
for (float ang=-43;ang <= 222; ang = Mathf.LerpAngle(minAnlge, maxAngle, Time.time)
)
{
// if (z > 0)
// {
thisSpeedo.transform.eulerAngles = new Vector3 (0, 0, ang);
//}
//else if (z<0)
// {
// thisSpeedo.transform.Rotate(0, 0, -ang);
// }
}
}
}