Created
February 1, 2017 05:17
-
-
Save sirokm007n/7e0320b4fb1f67057eabf51591b5eafe to your computer and use it in GitHub Desktop.
ブログ『Unity講座chap4』スクリプト『Box_generation.cs』
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
using UnityEngine; | |
using System.Collections; | |
public class Box_generation : MonoBehaviour { | |
//プレハブ(白と赤のCube(ボックス))を変数に代入 | |
public GameObject cube;//白のCube(ボックス) | |
public GameObject cube1;//赤のCube(ボックス) | |
private float time;//ボックス生成時間 | |
void Start () { | |
time = 0.5f; | |
} | |
void Update () { | |
//0.5秒間隔でボックス生成。60秒で120個のボックス生成。 | |
time -= Time.deltaTime; | |
if (time <= 0.0) { | |
time = 0.5f; | |
//白か赤どちらのCube(ボックス)を生成するかを格納 | |
int boxFlag = Random.Range (0, 1+1); | |
if(boxFlag == 0){//boxFlagの値が0なら白のCube(ボックス)を生成 | |
//白のCube(ボックス)の出現座標 | |
float x = -0.249f; | |
float y = 2.489f; | |
float z = Random.Range(-2.27f, -11.78f); | |
//白のCube(ボックス)生成 | |
Instantiate(cube, new Vector3(x, y, z), Quaternion.identity); | |
}else if(boxFlag == 1){//boxFlagの値が1なら赤のCube(ボックス)を生成 | |
//赤のCube(ボックス)の出現座標 | |
float x = -0.249f; | |
float y = 2.489f; | |
float z = Random.Range(-2.27f, -11.78f); | |
//赤のCube(ボックス)生成 | |
Instantiate(cube1, new Vector3(x, y, z), Quaternion.identity); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment