Time.timeScale not working properly?

Hi Everyone!

I have a little script:

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

public class CanvasScriptDis : MonoBehaviour {
    
    public Image img;
    public Image img2;
    public Image img3;
    public Text t1;
    public Text t2;
    public Text t3;
    public Button b1;
    public Button b2;

    public bool SecondNext;

    private void Start()
    {
		img.enabled = false;
		t1.enabled = false;
		t2.enabled = false;
		t3.enabled = false;
		b1.enabled = false;
		b2.enabled = false;
        img2.enabled = false;
        img3.enabled = false;
    }
    // Update is called once per frame
    void Update () {
        if (Input.GetButtonDown("Cancel") && !SecondNext) 
        {
            img.enabled = true;
			t1.enabled = true;
            t2.enabled = true;
			t3.enabled = true;
			b1.enabled = true; 
			b2.enabled = true;
			img2.enabled = true;
			img3.enabled = true;
            SecondNext = true;
            Time.timeScale = 0f;
        } else if (Input.GetButtonDown("Cancel") && SecondNext)
        {
			img.enabled = false;
			t1.enabled = false;
			t2.enabled = false;
			t3.enabled = false;
			b1.enabled = false;
			b2.enabled = false;
			img2.enabled = false;
			img3.enabled = false;
            SecondNext = false;
            Time.timeScale = 1f ;

        }
	}
}

if i press that button, the time doesn’t stop for some reason. am i doing something wrong?
Thanks.

Setting timeScale to 0 has only one effect, it will make Time.deltaTime to return “0”. That means that Time.time is no longer incremented (since it’s increased by Time.deltaTime). Everything that relies on deltaTime will basically stop.

However if you move something without deltaTime of course it won’t “stop”. If you do use Time.deltaTime for any kind of movement, make sure you don’t set Time.timeScale somewhere else back to 1.