Skip to content

Instantly share code, notes, and snippets.

@uranuno
Last active June 12, 2016 15:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uranuno/5678273 to your computer and use it in GitHub Desktop.
Save uranuno/5678273 to your computer and use it in GitHub Desktop.
Time.timeScale = 0にしたときも動く、WaitForSeconds(Unity)
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();
}
}
}
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!");
}
}
@uranuno
Copy link
Author

uranuno commented May 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment