Unity C# 初級編程| 15 . 基礎(chǔ)數(shù)學(xué)(Random)
Random 隨機函數(shù)
1.Random.Range ? ? ?隨機產(chǎn)生數(shù)
2.Random.rotation ? ? 隨機角度
練習(xí)1
隨機控制角度
場景中創(chuàng)建10個物體,創(chuàng)建一個腳本

腳本創(chuàng)建一個Object數(shù)組 ,在外部設(shè)置10個

指定到數(shù)組里面

代碼實現(xiàn)
用到了,上面學(xué)習(xí)到的for循環(huán) ,效果。

擴展:
在一個空間范圍生成這些物體,怎么辦?
注意,定義類型不同產(chǎn)生的效果也不同。float ?類型后面數(shù)字0f。
3.Random.value ? ? ? ? ? ? ? 0 到 1的隨機數(shù)
4.Random.seed ? ? ? ? ? ? ?隨機數(shù)的種子不變的
總結(jié):
Random.seed = 1; ? ? ?//隨機數(shù)種子 ? ? ?
Debug.Log(Random.Range(0,10)); ? ?
//從0到10產(chǎn)生的隨機數(shù),輸出效果每次都產(chǎn)生的一樣
資料參考
https://blog.csdn.net/zerrone/article/details/60781898
標(biāo)簽: