I want to be able to change the color of a treasure chest when it is moused over.
I have an array for the 2 parts of the chest(cylinder and box) and one for the default colors. For whatever reason, it is not grabbing the color in the array.
public GameObject[] chestParts;
private Color[] _defaultColors;
Start()
_defaultColors=new Color[chestParts.Length];
if(chestParts.Length > 0)
for(int ctr=0;ctr< _defaultColors.Length; ctr++)
_defaultColors[ctr]=chestParts[ctr].renderer.material.GetColor("_Color");
private void Highlight(bool glow){
if(glow){
if(chestParts.Length > 0)
for(int ctr=0;ctr< _defaultColors.Length; ctr++)
chestParts[ctr].renderer.material.SetColor("_Color", Color.yellow);
}
else{
for(int ctr=0;ctr< _defaultColors.Length; ctr++)
chestParts[ctr].renderer.material.SetColor("_Color", _defaultColors[ctr]);
}
}
What am I missing?
Thanks!
ok Here is your grail, it would be too long to write so I just give you the link.
Part 3 he actually gets the chest glowing after at 8.46. so I guess that is what you need.
With the help of perchik, I was able to get the glow working.
First thing was to lose the array(rather silly for only 2 items). Instead I used two variables:
private Color _defaultColor1;
private Color _defaultColor2;
Then for the declaration under Start()
if(chestParts.Length > 0)
_defaultColor1=chestParts[0].renderer.material.GetColor("_Color");
_defaultColor2=chestParts[1].renderer.material.GetColor("_Color");
Finally, in the function called glow:
private void Highlight(bool glow){
if(glow){
if(chestParts.Length > 0)
chestParts[0].renderer.material.SetColor("_Color", Color.green);
chestParts[1].renderer.material.SetColor("_Color", Color.green);
}
else{
chestParts[0].renderer.material.SetColor("_Color", _defaultColor1);
chestParts[1].renderer.material.SetColor("_Color", _defaultColor2);
}
}
There you go, a working glow. Unity only supports: red, green, yellow, magenta, white, black, gray or transparent for named values.