【发布时间】:2017-04-10 18:17:24
【问题描述】:
我的游戏对象开始搁在地板上。 isKinematic 设置为 true,并且 box collider 上的触发器设置为 true。
当玩家接触到对撞机时。它将游戏对象向下移动到地板。然后我将 isKinematic 设置为 false 并将触发器设置为 false。这会迫使游戏对象下落,直到它撞到地板并停止。我的问题是在游戏对象撞到地板并停止之后。我无法让 GameObject 识别它与地板相撞。我在 OnCollisionEnter2D 和 OnCollisionStay2D 中有一个 Debug.Log 语句。当它们触摸时,Debug.Log 不会出现在控制台中。这是为什么呢?
游戏对象有一个刚体和盒子碰撞器。地板上还有一个盒子对撞机和刚体。
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log ("Player is touching the section");
//sectionRigidbody.isKinematic = true;
if (readyToDrop == false)
//moves player
transform.position += newPosition;
readyToDrop = true;
sectionRigidbody.isKinematic = false;
sectionBoxCollider.isTrigger = false;
sectionRigidbody.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
//sectionRigidbody.isKinematic = true;
}
}
void OnCollisionEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Floor")
{
Debug.Log ("section is touching the floor");
}
}
void OnCollisionStay2D(Collider2D col)
{
if (col.gameObject.tag == "Floor")
{
Debug.Log ("section is touching the floor");
}
}
【问题讨论】:
-
把你所有的 Debug.Log 放到 if 标记语句之外然后再测试
-
把它移到外面,仍然没有@Programmer
-
发布附加到 GaemObject 的组件的屏幕截图。
-
@Programmer 我已经用你要求的图片编辑了原始版本
-
您好,我检查了您的图片,设置看起来不错。你说的是“我的游戏对象开始放在地板上。isKinematic 设置为 true,并且 box collider 上的触发器设置为 true” 但根据您刚刚上传的图像,这不是真的
标签: unity3d 2d graphics2d gameobject