- Home /
Time hasn't stopped
Ok so i have a start screen that shows a sprite before the game begins. You are supposed to click the left mouse button to start the game. The problem is that when the game starts, the menu pops up, but the game still runs in the background even though I set time.timescale = 0. I did a debug to see if the time was actually being set to zero and my debug said that it was. here is code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StartGame : MonoBehaviour {
public static bool sawOnce = false;
// Use this for initialization
void Start () {
if (sawOnce == false) {
this.GetComponent <SpriteRenderer> ().enabled = true;
Time.timeScale = 0f;
}
}
// Update is called once per frame
void Update () {
if (Time.timeScale == 0f) {
Debug.Log ("Time has stopped!");
}
}
}
Answer by jdean300 · Aug 06, 2017 at 08:36 AM
Your game still plays when you have Time.timeScale == 0f
but Time.deltaTime
will be zero. This means that any calculations based off of time (such as movement code) will be for the most part deactivated. If you have code running that does not use Time.deltaTime
at all, it will run as normal.
Your answer
Follow this Question
Related Questions
Stop Watch start when told 2 Answers
if and invoke repeating in start... 1 Answer
split-screen 'ready up' game start screen 0 Answers
Menu not working properly 1 Answer
Pause menu doesn't pause everything 0 Answers