Created
April 7, 2015 06:18
-
-
Save tsubaki/8717374f39cbb1d4e069 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 CoroutineSample1 : MonoBehaviour | |
{ | |
void OnMouseDown() | |
{ | |
StartCoroutine(ChangeColorCoroutine()); | |
} | |
IEnumerator ChangeColorCoroutine() | |
{ | |
var left = new WaitCoroutine(); | |
var right = new WaitCoroutine(); | |
var leftCoroutine = StartCoroutine(left.ChangeColorCoroutineWithRuntimetime()); | |
var rightCoroutine = StartCoroutine(right.ChangeColorCoroutineWithRuntimetime()); | |
yield return leftCoroutine; | |
yield return rightCoroutine; | |
// 待機時間の合計をログに出力 | |
var sum = left.waitSec + right.waitSec; | |
Debug.Log(sum); | |
} | |
} | |
class WaitCoroutine | |
{ | |
public float waitSec {get; private set;} | |
public IEnumerator ChangeColorCoroutineWithRuntimetime() | |
{ | |
waitSec = Random.Range(0.2f, 1f); | |
yield return new WaitForSeconds(waitSec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment