Last active
August 29, 2015 14:18
-
-
Save tsubaki/e2b97bab9e00d36303b5 to your computer and use it in GitHub Desktop.
コルーチンの戻り値
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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