Timer and level restart Help plz

I am make a game that is similar to Super Monkey Ball Deluxe and I need a countdown timer and once that timer runs out the level restarts. I have been looking around for a while and cant find anything. also if anyone can help me with my terrain controller it would be much appreciated.

Currently I’m using this code:

using UnityEngine;
using System.Collections;

public class TerrainController : MonoBehaviour {

    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
   
    float z = Input.GetAxis("Horizontal") * -15.0f;
Vector3 euler = transform.localEulerAngles;
euler.z = Mathf.Lerp(euler.z, z, 50.0f);
transform.localEulerAngles = euler;

    float x = Input.GetAxis("Vertical") * 15.0f;
Vector3 reuler = transform.localEulerAngles;
reuler.x = Mathf.Lerp(reuler.x, x, 50.0f);
transform.localEulerAngles = reuler;

    }
}

on a cube that you can’t collide with or see and making the cubes the ball rolls over a child of that object, however, it is very jumpy and you can glitch through the floor quite easily.

Really? because googling “unity countdown timer” and “unity restart level” comes up with loads of results and vids. Just be careful with the “LoadLevel” function, there were some changes done recently and it’s moved from “Application.LoadLevel(…)” to SceneManager.LoadLevel(…)". Both currently work, but use the newer sceneManager version.

huh?

Since you are using c# you can just launch a stopwatch and when that ends reload the level.
So you start a timer on void Start();
and in update check for it to end and reload the level.

Using System.Diagnostics;
SceneManager.LoadScene(1);
Stopwatch a = new Stopwatch();

for timer you can use something like these

var timeLimit = 60.0f//1 min
var currentTime = .0f;

void Start()
{
   InvokeRepeating("IncreaseTime",0, .1f);
}

void IncreaseTime()
{
   currentTime += .1f;

  if(currentTime > timeLimit )
  {
      //time up
  }
}
1 Like