Hi, I’m trying to change the color of a cube using a Vector4 (r,g,b,a) and the “a” is not changing correctly. The color starts at (255,255,255,55) typed directly in the inspector. With “a” as 55 i can get a transperent effect.
Then, I use the method OnMouseDown() to detect a click on the cube. The code is:
private bool isSelected;
private Color initialColor;
private Color selectedColor;
void Start(){
isSelected = false;
initialColor = new Vector4(255,255,255,55);
selectedColor = new Vector4(2,255,2,55);
}
void OnMouseDown(){
isSelected = ! isSelected;
if (isSelected){
gameObject.GetComponet<Renderer>().Material.color = selectedColor;
}
else {
gameObject.GetComponet<Renderer>().Material.color = initialColor;
}
}
That is it. when I select the cube it should change to transparent green and when I click again it deselects and should change the color back to white transparent. However, the colors are changing to initialColor (255,255,255,255) and selectedColor(2,255,2,255).
The Alpha color is always changing to 255.
Does anyone knows what is happening? Or a better for changing the color and keep the trasparent effect?