- Home /
Script to change colour makes GUItext invisible. Any idea why?
I'm using the following script to interpolate between multiple colours for some GUItext in a scene. But for some reason, the GUItext I attach this to disappears when I hit play. I've testing every otehr factor that I can think of, and it only seems to disappear when this script is attached and active. I've also attached it to a number of different objects in my scene, and modified it to change the colour of their rendering material and the same thing happens - the object dis appears when I hit play. Everything looks fine in the inspector, the color under the GUItext component changes as expected, etc. The object just doesn't appear in play.
If anyone can spot the error, I'd be very grateful.
public class ColourController : MonoBehaviour
{
public Color[] colors;
public int currentIndex = 0;
private int nextIndex;
public float changeColourTime = 2.0f;
private float timer = 0.0f;
//access the gameobject
GUIText titleColour;
void Start()
{
//access the gameobject
titleColour = GetComponent<GUIText>();
if (colors == null || colors.Length < 2)
{
Debug.Log ("Need to setup colors array in inspector");
}
nextIndex = (currentIndex + 1) % colors.Length;
}
void Update()
{
timer += Time.deltaTime;
//creates a timer that loops from 0 to 1 and makes things happen when it reaches 1
if (timer > changeColourTime)
{
currentIndex = (currentIndex + 1) % colors.Length;
nextIndex = (currentIndex + 1) % colors.Length;
timer = 0.0f;
}
titleColour.color = Color.Lerp(colors[currentIndex], colors[nextIndex], timer / changeColourTime );
}
}
Thanks, Matt
Answer by robertbu · Apr 28, 2014 at 10:06 PM
In the Inspector, go to your array of colors. Click each color to bring up the color picker and change the value of 'A' to 255.
Answer by SleazyDutcham · Oct 07, 2017 at 01:01 AM
Lol wow just had the same issue. Thanks @robertbu and @matski53 .
Is this really a "mistake" though? Why does the editor default to full transparency instead of full opaque? To me, seems illogical to have the editor behave that way.