2个对象之间的碰撞C#

时间:2014-11-03 17:49:17

标签: c# colors unity3d kinect collision

using UnityEngine;
using System.Collections;

public class CollisionExample : MonoBehaviour {

void OnCollisionEnter (Collision other){
    if(other.gameObject.name == "joint_HandRight")
    {
        this.gameObject.renderer.material.color = Color.green;
    }
}

void OnCollisionStay (Collision other){
    if(other.gameObject.name == "joint_HandRight")
    {
        this.gameObject.renderer.material.color = Color.green;
    }

}

void OnCollisionExit (Collision other){
    if(other.gameObject.name == "joint_HandRight")
    {
        this.gameObject.renderer.material.color = Color.red;
    }
 }
}

Í有一个名为TorusPro的圆环对象和一个名为joint_HandRight的方框对象。 这是我在脚本上使用的代码,它连接到我的Torus对象。当名为joint_HandRight的对象发生碰撞时,我希望它的颜色发生变化。它不起作用。为什么呢?

1 个答案:

答案 0 :(得分:0)

1. 两者 GameObjects必须有碰撞者
2.其中一个对撞机必须附有非运动刚体 3.检查碰撞矩阵以查看是否启用了图层之间的碰撞 4. meshCollider 不会与meshCollider发生碰撞