- Home /
Changing a Game Object's RGBA Value on Collision (JS)
I have a cube (Player) I want it to change color upon collision which I have I have achieved using
function OnTriggerEnter
(Player : Collider)
{
Player.gameObject.renderer.material.color = Color.green;
}
This works well but I am trying to change the object color with more control using RGBA. After digging around the forums I tried this: function OnTriggerEnter
(Player : Collider)
{
Player.ObjectName.renderer.material.SetColor("_TintColor", Color(23, 2, 13, 2));
}
This has no problems running but there is no change of color on collision - can anyone help point out where I am going wrong! Much appreciated!
Cheers
Answer by Seth-Bergman · Jul 23, 2013 at 07:13 PM
Color is a struct, and can be used the same as a predefined color (like Color.green):
Player.gameObject.renderer.material.color = Color(.23,.2,.13,.2);
Seth,
I am working with the following code now and on collision the object simply disappears (maybe the same as the background colour)
function OnTriggerEnter
(Player : Collider)
{
Player.gameObject.renderer.material.color = Color(242,118,73,100);
}
Any thoughts?
first off, please don't post comments as new answers, just use the comment tab.
now, see here:
http://docs.unity3d.com/Documentation/ScriptReference/Color-operator_Vector4.html
(and here)
http://docs.unity3d.com/Documentation/ScriptReference/Color.html
color values range from 0 to 1, adjusted..
(also, if my answer [or any answer] does solve your issue, please remember to check the mark to accept it..)
and finally, welcome to the forums!
Thanks Seth, worked out to just divide the RGB number by 256 which would give me the integer that I needed - working fine now thanks!