guiTexture.color changing

Im trying to change the color of my guiTextures in my interface. trying to save file size and figured that changing the color slightly to create a roll over effect would work just fine instead of switching out textures. After much searching i cant seem to figure out the correct method to impliment this script. Here is what im trying:

var NormColor : color;
var OverColor : color;



 
function Awake () {
   NormColor.color=(.5, .5, .5, 1);
   OverColor.color=(.3, .3, .3, 1);
}
   
//  rollover processing
function OnMouseEnter () {
	guiTexture.color = Color.OverColor;
}

function OnMouseExit () {
	guiTexture.color = Color.NormColor;
}

Thank you for taking a look, Im sure its a small usage error of .color and how to properly set the values but i searched all over for someone directly trying to change the colors of a guiTexture and cant find our how to use it!

Some problems: a color is type “Color” rather than “color” (all types use upper-case, which is why it’s good practice to use lowercase for variables to distinguish them visually). Also you refer to it by just the variable name; the “Color.something” syntax is for pre-defined colors like Color.green, Color.red, etc. Using public variables but then overriding them in Awake kind of removes the point of using public variables in the first place. I would do this:

var overColor = Color.green;  // It's nice to provide some kind of default
private var normalColor : Color;

function Awake () {
	normalColor = guiTexture.color;
}

function OnMouseEnter () { 
	guiTexture.color = overColor;
}

function OnMouseExit () { 
	guiTexture.color = normalColor;
}

That way you can set the mouseover color in the inspector, and the regular color is just taken from whatever the color normally is.

–Eric

1 Like

thanks for your reply!

The only place that I’m still stuck with is how do i control the color more precisely? you say

var overColor = Color.green;

But instead of green, how can i create my own rgba valued colors instead of default green.

Thanks for the advice about capital letters and types, im definitely an artist first, scripter 2nd… more like 5th haha :slight_smile:

EDIT

Well i got it working well enough for my liking for now but any better way to do this is always welcome. here is what i have.

private var over=false;
private var show_lessons=false;
  
function Update() {
if (over==true)
{
guiTexture.color.b = 0;
}
else{
guiTexture.color.b = .5;
}
}
 
//  rollover processing
function OnMouseEnter () {
	over=true;
}

function OnMouseExit () {
	over=false;
}

You can use

var overColor = Color(.3, .3, .3, 1.0);

Whatever you set it to in the inspector overrides that value anyway.

–Eric