2016-09-03 49 views
0

我有一個Physcis2D.OverlapCircle問題。在一篇教程中,我看到有人用它作爲地面探測器。我試圖用它來檢查玩家是否在平臺之上。我所做的是我在每個平臺上創建了空的gameObject。然後,我把一個腳本就可以在這裏我寫道:Physics2D.OverlapCircle不起作用

public bool onTop; 
public LayerMask whatIsTop; 
public float topCheckRadius; 
public Transform topCheck; 

void FixeUpdate() 
{ 
onTop = Physics2D.OverlapCircle(topCheck.position, topCheckRadius, whatIsTop); 
if (onTop) 
{ 
    Debug.Log("Works!"); 
} 
} 

然後在檢查我把空物體做爲topCheck.position,我把爲topCheckRadius一定的價值,最後我創建了一個名爲頂層,然後我在WhatIsTop層掩碼中選擇它。

但是,當我在玩家的平臺上跳躍時什麼也沒有發生。

回答

0

嗨,我想,這可能有助於2d-check-if-player-is-on-the-ground

告訴我你上:)

bool isGrounded = false; 
public Transform GroundCheck1; // Put the prefab of the ground here 
public LayerMask groundLayer; // Insert the layer here. 

void Update() { 
    isGrounded = Physics2D.OverlapCircle(GroundCheck1.position, 0.15f, groundLayer); 
    // checks if you are within 0.15 position in the Y of the ground 
}