public static float timeSinceLevelLoad;
Описание
Время, прошедшее с начала этого кадра (только для чтения). Это время в секундах с момента завершения загрузки последней неаддитивной сцены.
Это ведет себя так же, как Time.time с отрицательным смещением.
//Прикрепите этот скрипт к GameObject
//Создаем Кнопку (Create>UI>Кнопку) и текст GameObject (Создать>UI>Текст)
//Щелкните GameObject и прикрепите Кнопку и текст к полям в Инспекторе
//Этот скрипт выводит время с момента последней загрузки уровня. Это также позволяет вам загрузить новую Сцену, нажав Кнопку. Когда эта новая Scene загружается, время сбрасывается и обновляется.
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class TimeSinceLevelLoad : MonoBehaviour
{
public Button m_MyButton;
public Text m_MyText;
void Awake()
{
// Don't destroy the GameObject when loading a new Scene
DontDestroyOnLoad(gameObject);
// Make sure the Canvas isn't deleted so the UI stays on the Scene load
DontDestroyOnLoad(GameObject.Find("Canvas"));
if (m_MyButton != null)
// Add a listener to call the LoadSceneButton function when the Button is clicked
m_MyButton.onClick.AddListener(LoadSceneButton);
}
void Update()
{
// Output the time since the Scene loaded to the screen using this label
m_MyText.text = "Time Since Loaded : " + Time.timeSinceLevelLoad;
}
void LoadSceneButton()
{
// Нажмите эту Кнопку, чтобы загрузить другую Сцену.
// Загружаем Сцену с именем "Scene2"
SceneManager.LoadScene("Scene2");
}
}