Skip to content

Instantly share code, notes, and snippets.

@IshidaGames
Created October 30, 2019 12:25
Show Gist options
  • Save IshidaGames/3cfc9f8ad3710706ac3b558a95911b06 to your computer and use it in GitHub Desktop.
Save IshidaGames/3cfc9f8ad3710706ac3b558a95911b06 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HalloweenSystem : MonoBehaviour {
//Inspectorから配列にオブジェクトを設置
public GameObject[] character;
//設置するオブジェクト数
int characterNum = 5;
//ランダムに選んだオブジェクトの要素数
int randomNum;
//オブジェクトを出すX軸の位置の最大数値
float characterPos = 10;
//ランダムに選んだX軸の位置
float randomPos;
//数えた秒数を入れる
float time;
//何秒ごとにオブジェクトを出すか
float interval = 0.5f;
void Update () {
//秒数を計って変数に入れる
time += Time.deltaTime;
//timeの数値がintervalを超えたら働く
if(time > interval)
{
//timeを0に戻す
time = 0;
//配列の要素数とX軸の位置をランダムで選ぶ
randomNum = Random.Range(0, characterNum);
randomPos = Random.Range(0, characterPos);
//Prefabのオブジェクトを生成する
GameObject copy = Instantiate(character[randomNum],
//生成したものを配置する位置
new Vector3(
//X軸
randomPos,
//Y軸
0,
//Z軸
0
//Quaternion.identityは無回転を指定する
), Quaternion.identity
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment