Skip to content

Instantly share code, notes, and snippets.

@aidiary
Last active October 11, 2018 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aidiary/e867a474440d78d6fb6b to your computer and use it in GitHub Desktop.
Save aidiary/e867a474440d78d6fb6b to your computer and use it in GitHub Desktop.
円運動しながらマウスクリックでコインを出す
#pragma strict
// CoinSource.js
// 生成するCoinオブジェクト
// InspectorでCoinのPrefabをセットする
var coinObject : GameObject;
function Start () {
// 乱数シードを初期化
Random.seed = System.Environment.TickCount;
}
function Update() {
// 原点を中心に円運動させる
transform.RotateAround(Vector3.zero, Vector3.up, 100 * Time.deltaTime);
// マウスクリックしたらコインを出す
if (Input.GetMouseButtonDown(0)) {
for (var i = 0; i < 5; i++) {
var clone : GameObject;
clone = Instantiate(coinObject, transform.position, transform.rotation);
clone.rigidbody.velocity.x = 10 * Random.Range(-1.0, 1.0);
clone.rigidbody.velocity.y = 50 * Random.Range(-1.0, 1.0);
clone.rigidbody.velocity.z = 10 * Random.Range(-1.0, 1.0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment