I am trying to get a clock tower to rotate it's analog time according to the actual time.
However, the mesh or materials won't rotate using the "DateTime.Now.TimeOfDay; hours.localRotation = Quaternion.Euler" method. It stays still. Can anyone please help?
Code:
private const float
hoursToDegrees = 360f / 12f,
minutesToDegrees = 360f / 60f,
secondsToDegrees = 360f / 60f;
public Transform hours, minutes, seconds;
public bool analog;
void Update()
{
if (analog)
{
TimeSpan timespan = DateTime.Now.TimeOfDay;
hours.localRotation =
Quaternion.Euler(0f, 0f, (float)timespan.TotalHours * -hoursToDegrees);
minutes.localRotation =
Quaternion.Euler(0f, 0f, (float)timespan.TotalMinutes * -minutesToDegrees);
seconds.localRotation =
Quaternion.Euler(0f, 0f, (float)timespan.TotalSeconds * -secondsToDegrees);
print(timespan);
}
else
{
DateTime time = DateTime.Now;
hours.localRotation = Quaternion.Euler(0f, 0f, time.Hour * -hoursToDegrees);
minutes.localRotation = Quaternion.Euler(0f, 0f, time.Minute * -minutesToDegrees);
seconds.localRotation = Quaternion.Euler(0f, 0f, time.Second * -secondsToDegrees);
}
}
}