0

I am trying to get a ball to pass trough an empty object but also send back a message to debug window. But I don't have a clue how to do this or where to start, so any help on this would be greatly appreciated. I am sorry I have no code to show as an example, however I have been able to get a collision detection or to allow the object pass through the empty object one at a time but never both. I have used OnTriggerEnter and OnCollionEnter.

4

2 回答 2

2

在您的空对象上放置一个Collider(例如 a SphereCollider),并将其设置Is Triggertrue. 现在您可以OnTriggerEnter按预期在脚本中使用(附加到空对象)。

public class MyBehaviour : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        var collider = other.gameObject;
        // Do something...
        Debug.Log(collider);
    }
}
于 2013-02-19T20:54:23.200 回答
0

你想让你的游戏对象的对撞机成为编辑器上的触发器。转到编辑器并将对撞机添加到您的游戏对象,然后将其设为触发器。

C# 代码

void OnTriggerEnter(Collider other)
{
    Debug.Log("I hit something: " + other.gameObject);
}

Javascript

function OnTriggerEnter (other : Collider) 
{
    Debug.Log("Hey I hit you: " + other.gameObject);
}
于 2013-02-20T00:41:35.700 回答