I made a very simple clock on Unity for practice, but for some reason the color of the hands won’t change. I’m pretty sure I scripted it right and when I hit play the mesh render shows the correct color for the hands but that color isn’t actually displayed. They seem to just stay a grey color. Here’s my script and a screen shot of my Unity window. Thanks.
[24043-screen+shot+2014-03-22+at+12.20.58+pm.png|24043]
using UnityEngine;
using System;
public class ClockAnimator : MonoBehaviour {
private const float
hoursToDegrees = 360f / 12f,
minutesToDegrees = 360f / 60f,
secondsToDegrees = 360f / 60f;
public Transform hours, minutes, seconds;
public bool analog;
void Start () {
GameObject ClockBack = GameObject.FindGameObjectWithTag ("Back");
ClockBack.renderer.material.color = Color.black;
GameObject [] HandsArray = GameObject.FindGameObjectsWithTag ("Hand");
foreach (GameObject hand in HandsArray) {
hand.renderer.material.color = Color.yellow;
}
}
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);
}
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);
}
}
}