Correct usage of GUITexture.color

I experience problems using the color method to change the color a GUITexture

I have a GUITexture based on a png with pure {RGBA(1.000, 0.000, 0.000, 1.000)}

In my script I want to change this one to green by using

public var Display : GUITexture;

function Start()
{
    Display.color = Color.green;
}

The GUITexture is assigned via the inspector (drag and drop a single png file). The original png file is a single square with the color rgb(255, 0, 0).

On the debugger I can see before executing this line

MyTexture.color is {RGBA(1.000, 0.000, 0.000, 1.000)}

color.green is {RGBA(0.000, 1.000, 0.000, 1.000)}

After execution I get:

MyTexture.color {RGBA(1.000, 0.922, 0.016, 1.000)}

If I change the color of the texture in the Inspector in the GUITexture I have similar effects the color set is not the color on screen. The same applies also if I want to manipulate the color of a SpriteRenderer object.

My assumption is that the initial color of the png still effects this setting. Is this intended behavior?

How can I apply a color to a GUITexture without this effect?

This is the only instance and it is used once and accessed from any other object.

2 Answers

2

Note that the code above will not compile indicating that this is not your real code. In addition we don’t see how you are initializing ‘GUITexture’. GUITexture.color specifies a overlay or tint color. The color specified is combined with the texture. But the value of GUITexture.color should be the color you set, not something else. Something is going on…multiple copies of the script…wrong GUITexture reference…etc…but there is not enough information here to figure it out.

Thanks for the initial feedback. I have edited the post: - added the assignment (drag&drop via the inspector) - Multiple access can be eliminated

When I execute your code and then do a Debug.Log of Display.color, I get: RGBA(0.000, 1.000, 0.000, 1.000) ...as expected. So something else is going on. Can you create a small package of this behavior and put it on the net and attach a link to your question?

I tested the project you attached and it seems to be a bug. Please submit a bug report with that sample project:

I will submit a bug report. It just came to my mind that it could be an "odd png" It was generated by inkscape via export...