我無法創建一種方法來檢查播放器是否與某個「航點」發生碰撞,如果我單擊該航點。我已經設置了玩家希望能夠移動到的7個路點。驗證單擊後是否與某個對象發生碰撞
現在我正在嘗試編寫一段腳本,檢查點擊後的路點(onMouseDown)是否與玩家發生碰撞。因爲如果是這種情況,它不會計算移動到的位置。
public class WayPointPositioner : MonoBehaviour {
private Vector3 wayPointPosition;
public GameObject playercheck;
//Check if object is clicked
void OnMouseDown()
{
Debug.Log ("Object Clicked " + GameObject.name);
// Check if collision occurs with playercheck
OnCollisionEnter(playercheck != Collision)
{
// If its the player, then return a new position for the player to move to for walking
// Else debug that its not so
if (playercheck.gameObject.CompareTag("Player"))
{
Debug.Log ("Object not colliding and retrieving position");
wayPointPosition = new Vector3 (GameObject.X, GameObject.Y, 10);
wayPointPosition = Camera.main.ScreenToWorldPoint(wayPointPosition);
}
else
{
Debug.Log ("Object is colliding, no movement needed");
}
}
}
}
現在我已經知道OnCollisionEnter
將無法正常工作。因爲它需要在它之前運行的void-statement。但我不知道我能做到這一點。
不,航點系統在那裏,所以玩家角色最終會沿着航點移動到航點的目的地。示例:他從Waypoint 02開始,需要前往Waypoint 06,然後在03-04-05之間前進至06。 – Veraduxxz 2014-09-22 12:00:24