- Home /
Question by
TonyTCB · Aug 03, 2020 at 07:28 AM ·
collisiontriggercolliderscollision detectiontriggers
Trying to make object turn red OnTriggerEnter
I am trying to make a cube where if an object with powered tag collides with trigger collider of the cube it turns red and gets powered tag. If no powered tag objects are touching it it should be gray and unpowered. Unity does not return an error but it doesn't do anything regardless.
void OnTriggerEnter(Collision collision)
{
if (collision.rigidbody.tag == "powered")
{
this.tag = "powered";
this.GetComponent<Material>().SetColor("_Color", Color.red);
}
else
{
this.tag = "unpowered";
this.GetComponent<Material>().SetColor("_Color", Color.gray);
}
}
Comment
we cant help you with this information the code is fine check if one of the objects has a rigidbody and both have colliders and istrigger atleast one