2 个对象 C# 之间的冲突

本文关键字:冲突 之间 对象 | 更新日期: 2023-09-27 18:29:08

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的对象发生碰撞时,它的颜色会发生变化。它不起作用。为什么?

2 个对象 C# 之间的冲突

1.两个游戏对象都必须有碰撞体
2.其中一个对撞机必须连接
非运动刚体3.检查碰撞矩阵以查看是否启用了
图层之间的碰撞4.网状对撞机不会与网状对撞机
碰撞