When the First Person Controller hits a cube i need to know if the color of the cube is red, do something.
The best i could take was:
RGBA(1.000, 0.000, 0.000, 1.000).
If there is another post with this question, sorry.
Thank you so much everyone.
This is the code that i use.
var cube : Transform;
function Start ()
{
cube.renderer.material.color = Color.red;
}
If the player controller and cubes have appropriate colliders and rigidbodies then you can place this code in a script on your player:
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "cube") { //use the tag system to identify cubes
Renderer renderer= collision.gameObject.GetComponent<Renderer>();
if (renderer) {
Color color = renderer.material.color;
// handle a collision now that we know the color
}
}
}
I’m not sure what you want to do next.
Your question mentions determining if it is red:
if (color == Color.red)
Or if you would like to know if it’s red component is above a threshold:
if (color.r > 0.5f)
You also mention creating a string representation, but don’t specify a format. If you are looking for web-style hex codes then you may want to look at HexConverter on the wiki.