Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created September 20, 2020 04:38
Show Gist options
  • Save todorok1/7e32107de6c3e8bf418a54bd07b931dc to your computer and use it in GitHub Desktop.
Save todorok1/7e32107de6c3e8bf418a54bd07b931dc to your computer and use it in GitHub Desktop.
コルーチンで処理を待つサンプル
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <Summary>
/// コルーチンを使って処理を待つサンプルです。
/// </Summary>
public class WaitSample : MonoBehaviour
{
void Start()
{
// コルーチンを開始します。
StartCoroutine(WaitProcess());
}
/// <Summary>
/// コルーチンで処理を待ちます。
/// </Summary>
IEnumerator WaitProcess()
{
// 1フレーム処理を待ちます。
yield return null;
// 指定した秒数だけ処理を待ちます。(ここでは1.0秒)
yield return new WaitForSeconds(1.0f);
// 別のコルーチンの終了を待ちます。
yield return StartCoroutine(AnotherProcess());
}
/// <Summary>
/// WaitProcess()から起動されるコルーチンです。
/// </Summary>
IEnumerator AnotherProcess()
{
// 1フレーム処理を待ちます。
yield return null;
// なんらかの処理を行います。
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment