Making a Collider only collide with objects that don't share the same material color. (89645)

Without messing with physics layers(as I’d need different ones for every possible color) what is the best way to do this? I don’t want to enable/disable the collider based on what is touching it as if two objects hit it at the same it would cause problems.

Any suggestions appreciated, preferably in JS.

EDIT:

I have the following:

function OnCollisionExit (thingHit : Collision)
{
if(thingHit.gameObject.renderer.material.color == renderer.material.color)
Physics.IgnoreCollision(collider, thingHit.collider, false);

if(thingHit.gameObject == player)
manager.GetComponent(ColourChangeScript).switcherE nabled = true;
}

function OnCollisionEnter (thingHit : Collision)
{

if(thingHit.gameObject.renderer.material.color == renderer.material.color)
Physics.IgnoreCollision(gameObject.collider, thingHit.collider, true);

if(thingHit.gameObject == player)
manager.GetComponent(ColourChangeScript).switcherE nabled = false;
}

It isn’t ignoring the collisions at all. Any ideas?

Try this:

function OnCollisionEnter(col:Collision){
   StartCoroutine(disableCollisions(col.collider, this.collider, 2));
}
 
function disableCollisions(c1:Collider ,c2:Collider, seconds:double)
{
  Physics.IgnoreCollision(c1, c2, true);
  yield WaitForSeconds (seconds);
  Physics.IgnoreCollision(c1, c2, false);
}