如何检测两个相同颜色的物体何时发生碰撞?

How can detect when 2 objects collision with the same color?

我有 1 个问题 Unity:

我有 1 个物体与 2 个物体发生碰撞,第一个是蓝色的,第二个是红色的。

我想知道如何检测两个物体何时颜色相同并确定动作 两个物体之间的碰撞很清楚但是如何检测你的颜色对我来说太难了.

¿怎么办?

碰撞:

public class Colision : MonoBehaviour {

    //public GameObject HaloPrefab; // empty with halo applied to it...

    public Text points;


    void OnCollisionEnter(Collision col){


        if ( col.gameObject.name == "Cube") {

            col.gameObject.SetActive(false); // Lo que hago es que si colisiona desaparezca el objeto, pero necesito que haga eso si ambos son del mismo color. 
        }




        if ( col.gameObject.name == "Cube(Clone)") {

            col.gameObject.SetActive(false);


        }     
}

我的对象可以改变颜色,代码是这样的:并且有效

public class ChangeColor : MonoBehaviour {

    public Material[] materials;
    public Renderer rend;

    private int index = 1;

    // Use this for initialization
    void Start () {

        rend = GetComponent<Renderer> ();
        rend.enabled = true;

    }

    public void Update() {
        if (materials.Length == 0) {
            return;
        }
        if (Input.GetMouseButtonDown (0)) {
            index += 1;

            if (index == materials.Length + 1) {
                index = 1; 
            }
            print (index);

            rend.sharedMaterial = materials [index - 1];                        
        }
    }
}

像这样:

void OnCollisionEnter(Collision col)
{
    var me = gameObject.GetComponent<Renderer>();
    var other = col.gameObject.GetComponent<Renderer>();
    if (me != null && other != null)
    {
        if (me.sharedMaterial.color == other.sharedMaterial.color)
        {
            // congratulation you are colliding with same color.
        }
    }
}