初學者在這里。我試圖讓它在一個圓圈內找到一個隨機點,去那個點,然后捕捉到一個網格。
我已經能夠在圓圈內找到一個點并移動到那里,但我無法弄清楚任何作業方法。
這是查找并移動到圓內某個點的代碼。
private void RandomizePosition()
{
double x = -0.5; // center of circle x
double y = -0.5; // center of circle y
this.transform.position = UnityEngine.Random.insideUnitCircle * 7; // this makes the circle
}
我已經厭倦了使用this.transform.position = new Vector3(Mathf.Round(x), Mathf.Round(y), 0.0f);
,但我收到錯誤“無法將雙精度型別隱式轉換為浮點數”如果有人有任何想法,請分享,謝謝。
uj5u.com熱心網友回復:
Mathf.Round
將 afloat
作為其引數,并且您將 adouble
在其中傳遞。以下應該有效:
this.transform.position = new Vector3(Mathf.Round((float)x), Mathf.Round((float)y), 0.0f);
uj5u.com熱心網友回復:
直接使用float
:
var x = -0.5f; // center of circle x
var y = -0.5f; // center of circle y
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/471734.html
下一篇:返回列表