Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/e2b97bab9e00d36303b5 to your computer and use it in GitHub Desktop.
Save tsubaki/e2b97bab9e00d36303b5 to your computer and use it in GitHub Desktop.
コルーチンの戻り値
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CoroutineSample2 : MonoBehaviour
{
[SerializeField]
Renderer leftRenderer = null, rightRenderer = null;
void OnMouseDown()
{
StartCoroutine(ChangeColorCoroutine());
}
IEnumerator ChangeColorCoroutine()
{
float sum = 0;
var leftCoroutine = StartCoroutine(ChangeColorCoroutineWithRuntimetime(leftRenderer, (result)=> sum += result));
var rightCoroutine = StartCoroutine(ChangeColorCoroutineWithRuntimetime(rightRenderer, (result)=> sum += result));
yield return leftCoroutine;
yield return rightCoroutine;
// 待機時間の合計をログに出力
Debug.Log(sum);
}
IEnumerator ChangeColorCoroutineWithRuntimetime(Renderer renderer, UnityEngine.Events.UnityAction<float> callback)
{
float waitSec = Random.Range(0.2f, 1f);
yield return new WaitForSeconds(waitSec);
// 待機した時間を返す
callback(waitSec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment