Skip to content

Instantly share code, notes, and snippets.

@Buravo46
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Buravo46/10229648 to your computer and use it in GitHub Desktop.
Save Buravo46/10229648 to your computer and use it in GitHub Desktop.
【Unity】InvokeRepeating関数を使った、一定時間ごとにオブジェクトを生成する方法
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