Last active
August 29, 2015 14:18
-
-
Save tsubaki/cae009b41ede83981dc8 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; | |
void OnMouseDown() | |
{ | |
StartCoroutine(ChangeColorCoroutine()); | |
} | |
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