知道此代碼應該找到我在給定范圍內的幾個位置并將我的物件放置到這些位置。但它以某種方式無法運行一個簡單的 while 函式來找到這些位置
void SortCharacters()
{
int i = 1;
foreach (Transform child in Center.transform)
{
float x = 0;
float y = 0;
Debug.Log("**********************");
while (x * x y * y > 0.4f * 0.4f)
{
Debug.Log("-------------------");
Debug.Log("a: " x " b:" y);
x = (UnityEngine.Random.Range(0, 8) - 4) / 10;
y = (UnityEngine.Random.Range(0, 8) - 4) / 10;
}
float DistanceRoughly = (i / 6);
float CalculatedDistanceMultiplier = (float)Math.Round(DistanceRoughly, 0, MidpointRounding.AwayFromZero);
Vector3 pos = new Vector3(x, y, 0) * CalculatedDistanceMultiplier;
child.transform.position = pos;
i ;
Debug.Log("Found Obj: " child " x:" x " y:" y " Mult:" CalculatedDistanceMultiplier);
}
}
所以它會以應有的方式列印出星星、孩子和 mult。但它是說我的 x,y 都是 0 并且它不列印“-----------------”。PS:它也不會列印“a:b:”的東西
uj5u.com熱心網友回復:
這是因為在您的 while 回圈中,您正在檢查:
0 * 0 0 * 0 > 0.4f * 0.4f這是不正確的,因此它不會進入 while 回圈。你設定了float x = 0,float y = 0所以它正確地遵循了代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/440942.html
上一篇:Unity物件池物件不可見
