RoadRunner/Assets/script/sceneFlipper.cs
Kasper Karlgren c84494a697 new files
2025-01-21 13:54:40 +01:00

65 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
public class sceneFlipper : MonoBehaviour
{
public float delay = 430;
public bool goal = true;
[Header("timer")]
public TextMeshProUGUI timerText;
private float currentTime;
[Header("scene")]
public string sceneName = "runnerOG";
public void LoadScene(string sceneName) {
SceneManager.LoadScene(sceneName);
}
void Start(){
currentTime = delay;
}
private void Update()
{
currentTime = currentTime -= Time.deltaTime;
setTimerText();
if (currentTime < 0){
SceneManager.LoadScene(sceneName);
}
}
private void setTimerText()
{
timerText.text = currentTime.ToString("0");
}
IEnumerator LoadLevelAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
SceneManager.LoadScene(sceneName);
}
IEnumerator OnTriggerEnter(Collider collision)
{
Debug.Log("enter!");
if (goal)
{
Debug.Log("enter!");
if (collision.tag == "playercar")
{
yield return new WaitForSeconds(2);
Debug.Log("go player!");
SceneManager.LoadScene(sceneName);
}
}
}
}