Last active
August 29, 2015 14:18
-
-
Save tsubaki/6845e31dcd8b906001a1 to your computer and use it in GitHub Desktop.
コルーチン1サンプルの中断可能版
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; | |
public class CoroutineSample1 : MonoBehaviour | |
{ | |
bool isRunning = false; | |
Coroutine coroutine; | |
void OnMouseDown() | |
{ | |
coroutine = StartCoroutine(ChangeColorCoroutine()); | |
} | |
void OnMouseUp() | |
{ | |
StopCoroutine(coroutine); | |
ChangeColorCoroutine(renderer, Color.green); | |
isRunning = false; | |
} | |
IEnumerator ChangeColorCoroutine() | |
{ | |
if( isRunning ) { yield break; } | |
isRunning = true; | |
var renderer = GetComponent<Renderer>(); | |
ChangeColorCoroutine(renderer, Color.red); | |
// 0.5秒待つ | |
yield return new WaitForSeconds(0.5f); | |
ChangeColorCoroutine(renderer, Color.green); | |
isRunning = false; | |
} | |
void ChangeColorCoroutine(Renderer renderer, Color color) | |
{ | |
renderer.material.color = color; | |
DynamicGI.UpdateMaterials(renderer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment