Last active
October 11, 2018 00:47
-
-
Save aidiary/cd450313aaaa46723234 to your computer and use it in GitHub Desktop.
ランダムな初速を持つボールオブジェクトを生成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
// BallSourceController.js | |
// 生成するボールオブジェクト | |
// InspectorでBallのPrefabをセットする | |
var ballObject : GameObject; | |
function Start () { | |
// 乱数シードを初期化 | |
Random.seed = System.Environment.TickCount; | |
} | |
function OnGUI() { | |
// GUIメニューを作成 | |
GUI.Box(new Rect(10, 10, 140, 90), "Menu"); | |
// 初期化ボタン | |
if (GUI.Button(new Rect(20, 40, 120, 20), "Reset")) { | |
Application.LoadLevel("RigidbodyTest"); | |
} | |
// ボールオブジェクトを新たに生成 | |
// 初速はランダムにする | |
if (GUI.Button(new Rect(20, 70, 120, 20), "Create Balls")) { | |
for (var i = 0; i < 5; i++) { | |
var clone : GameObject; | |
clone = Instantiate(ballObject, transform.position, transform.rotation); | |
clone.rigidbody.velocity.x = 20 * Random.Range(-1.0, 1.0); | |
clone.rigidbody.velocity.y = 20 * Random.Range(-1.0, 1.0); | |
clone.rigidbody.velocity.z = 20 * Random.Range(-1.0, 1.0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment