Страница 1 из 1

Реализация WaitForGameSeconds()

СообщениеДобавлено: 14 янв 2010, 19:19
gnoblin
Практически полностью подтырил на оф.форуме... Очень полезно, когда есть свое "игровое время".
Код: Выделить всё
using UnityEngine;
using System.Collections;

public class TimeUtil : MonoBehaviour
{

    public Coroutine WaitForGameSeconds(float time)
    {
        return StartCoroutine(WaitForGameSecondsImpl(time));
    }

    private IEnumerator WaitForGameSecondsImpl(float time)
    {

        while (time > 0)
        {
            //change this line if necessary
            time -= Level.game_delta_time;//Time.deltaTime;

            yield return 1;
        }
    }

    void Start()
    {
        StartCoroutine(C());
    }

    IEnumerator C()
    {

        yield return WaitForGameSeconds(2);
        Debug.Log("Blabla!");
    }
}