- Home /
Question by
edwardgeorgefleming · Mar 30, 2020 at 01:07 AM ·
collisionmaterialcolor
Detecting the Green in a Material's Color on Collision
I am trying to determine if the green in a material's color is greater than 0.99f on a collision in C#?
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.GetComponent<Material>().color.g > 0.99)
{
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}
}
Comment
Answer by Namey5 · Mar 30, 2020 at 05:55 AM
'Material' isn't a component that can be added to an object. Instead, you'll need to get it from the renderer;
if (collision.gameObject.GetComponent<Renderer>().material.color.g > 0.99f)
{
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}