Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to create simple timer in Unity

Posted on October 7, 2017August 4, 2020 by Habibie

With this timer, we can load a scene and run this timer, that if this timer reaches it’s end, another scene will be loaded.

First we need to create a countDown variable, enter value in seconds, for example if you want 3 seconds for the timer, type this:

float countDown = 3f;

Put that code before Start() (outside any methods). Than, inside Update() method, make an if statement like this:

if (countDown > 0)
			countDown -= Time.deltaTime;
		else
			Application.LoadLevel ("StartScene");

Here is the full script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SimpleTimer : MonoBehaviour {

        float countDown = 3f;
	
	void Update () {
		if (countDown > 0)
			countDown -= Time.deltaTime;
		else
			Application.LoadLevel ("SomeScene");
	}
}
Post Views: 483
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme