我正在嘗試在給定區域內生成某些類型的拾音器,盡管有些通常會卡在墻壁內,我該如何解決?移動物體的相關代碼for (int x = 0; x < garbage.Length; x++) { if (x < 5) { garbage[x].transform.position = new Vector3(Random.Range(-33.0f, 30.0f), 2.35f, Random.Range(30.0f, -35.0f)); }}使用 Physics.OverlapSphere 修復了它。謝謝。
2 回答

慕無忌1623718
TA貢獻1744條經驗 獲得超4個贊
你的 if 語句中可以有一個 while 循環,所以它就像
int attempts = 0;
while(garbage[x].transform.position == /*[the range of coordinates for the wall]*/ || attempts = 0)
{
garbage[x].transform.position = new Vector3(Random.Range(-33.0f, 30.0f), 2.35f, Random.Range(30.0f, -35.0f));
attempts += 1;
}
- 2 回答
- 0 關注
- 187 瀏覽
添加回答
舉報
0/150
提交
取消