Last active
August 29, 2015 13:58
【Unity】InvokeRepeating関数を使った、一定時間ごとにオブジェクトを生成する方法
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; | |
/// <summary> | |
/// InvokeRepeating関数を使った、一定時間ごとにオブジェクトを生成するクラス | |
/// </summary> | |
public class ObjectCreater : MonoBehaviour { | |
/// <summary> | |
/// privateな変数をインスペクターから設定できるようにする | |
/// </summary> | |
[SerializeField] | |
/// <summary> | |
/// プレハブ | |
/// </summary> | |
private GameObject prefab; | |
/// <summary> | |
/// 待ち時間 | |
/// </summary> | |
private float waitingTime = 2.0f; | |
/// <summary> | |
/// 初期化 | |
/// </summary> | |
void Awake(){ | |
// InvokeRepeating("関数名",初回呼出までの遅延秒数,次回呼出までの遅延秒数) | |
InvokeRepeating("Create", waitingTime, waitingTime); | |
} | |
/// <summary> | |
/// オブジェクトの生成 | |
/// </summary> | |
void Create(){ | |
// インスタンス生成 | |
Instantiate(prefab, Vector3.zero, Quaternion.identity); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment