15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

数秒おきに処理を実行する【Unity】

Last updated at Posted at 2015-07-12

コルーチンを使用する

AS3のTimerみたいな一定時間おきに処理を実行するものがほしかったんですが、コルーチンがそれっぽかったです。

void Start () {
	// コルーチンを設定
	StartCoroutine(loop());
}

private IEnumerator loop() {
	// ループ
	while (true) {
		// 1秒毎にループします
		yield return new WaitForSeconds(1f);
		onTimer();
	}
}

private void onTimer() {
	// 1秒毎に呼ばれます
	Debug.Log("on timer");
}

yieldの意味がよくわかりません…

15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?