title: Unity how to check for color match
body: <p>I am using Unity 5 and wanted to check on collision if two game object material have the same matching color and to take action if the colours don't match. I am using the c# code below:</p>
  
  <pre><code>void OnCollisionEnter2D(Collision2D col)
  {
  
      if(col.gameObject.GetComponent&lt;Renderer&gt; ().material.color != this.gameObject.GetComponent&lt;Renderer&gt; ().material.color)
      {
          Destroy(col.gameObject);
      } 
  }
  </code></pre>
  
  <p>This doesn't appear to work properly as the sometimes the gameobject gets destroyed even when the color matches. Just wondering if there is another way to check for color matches?</p>