Last active
June 12, 2016 15:54
-
-
Save uranuno/5678273 to your computer and use it in GitHub Desktop.
Time.timeScale = 0にしたときも動く、WaitForSeconds(Unity)
This file contains hidden or 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 TimeUtils : MonoBehaviour | |
{ | |
//TimeScaleに関わらず、指定の秒数まつ | |
public static IEnumerator WaitForSecondsIgnoreTimeScale(float time) | |
{ | |
float targetTime = Time.realtimeSinceStartup + time; | |
while(Time.realtimeSinceStartup < targetTime) | |
{ | |
yield return new WaitForEndOfFrame(); | |
} | |
} | |
} |
This file contains hidden or 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 TimeUtilsTest : MonoBehaviour | |
{ | |
IEnumerator Start() | |
{ | |
//TimeScaleを0にしても動くかどうか確認 | |
Time.timeScale = 0; | |
//3秒まつ | |
yield return StartCoroutine(TimeUtils.WaitForSecondsIgnoreTimeScale(3f)); | |
Debug.Log("TestEnd!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unity5.3〜 http://blogs.unity3d.com/jp/2015/12/01/custom-coroutines/