Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
コルーチンの戻り値
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