简体   繁体   English

Unity 2d Box Collider 不触发 C#

[英]Unity 2d Box Collider Not Triggering C#

Using Unity 4.3.4f使用 Unity 4.3.4f

Scenario: I'm attempting to creating a background that moves with a camera object by using the Box Collider 2d and Rigidbody 2d attributes in order to create the feel that the background is looping as the camera moves across the screen.场景:我试图通过使用 Box Collider 2d 和 Rigidbody 2d 属性来创建一个随相机对象移动的背景,以创建当相机在屏幕上移动时背景在循环的感觉。

The background elements are set to Is Trigger and the object on my camera that includes the detection script has a kinematic 2d rigidbody.背景元素设置为 Is Trigger,并且我的相机上包含检测脚本的对象具有运动学 2d 刚体。 To test if this works I just added the below script in C# to see if they collide.为了测试这是否有效,我只是在 C# 中添加了以下脚本以查看它们是否发生冲突。

void OnTriggerEnter2d(Collider2D collider) {
    Debug.Log ("Collision: " + collider.name);
}

In theory this should of course print the name of the object the collider makes contact with, right?从理论上讲,这当然应该打印对撞机接触的对象的名称,对吗? For some reason I'm getting no output to my log.出于某种原因,我的日志没有输出。 Any suggestions on what I'm not seeing here or a document I could review to figure out my problem?关于我在这里没有看到的内容或我可以查看的文档以找出我的问题的任何建议?

You have a capitalization issue.您有大小写问题。

void OnTriggerEnter2D(Collider2D other) {
    //your handler code goes here!
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM