我的遊戲對象開始擱在地板上。 isKinematic被設置爲true,並且盒子對撞機上的觸發器被設置爲true。遊戲對象沒有檢測到與地板的碰撞
當玩家觸碰對撞機。它將GameObject向下移動到底部。然後,我將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
將它移動到外面,但仍然沒有任何內容@Programmer –
附加了GaemObject的組件的Post Screeenshot。 – Programmer