For some reason toggle.isOn = true
does not work when timescale is 0. I dont use any transitions or anything on the toggle component and I try to set it via script. Works fine when timescale is > 0.
Any ideas how I can get around this?
For some reason toggle.isOn = true
does not work when timescale is 0. I dont use any transitions or anything on the toggle component and I try to set it via script. Works fine when timescale is > 0.
Any ideas how I can get around this?
Are you sure?
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
// @kurtdekker
// drop this script on a Toggle suitably in a Canvas hierarchy
// press PLAY
// observe the blink
// press T to toggle time scale
// see timescale outputted in Debug.Log()
// observe steady blinking of toggle checkmark
// ???
// profit!
public class Gloggle : MonoBehaviour
{
Toggle t;
IEnumerator Start()
{
t = GetComponent<Toggle>();
// blinks the toggle on / off
while (true)
{
t.isOn = false;
yield return new WaitForSecondsRealtime(0.25f);
t.isOn = true;
yield return new WaitForSecondsRealtime(0.25f);
}
}
void Update()
{
// lets you pause / restart time
if (Input.GetKeyDown(KeyCode.T))
{
Time.timeScale = (Time.timeScale == 0) ? 1 : 0;
Debug.Log("Timescale is now: " + Time.timeScale);
}
}
}
So strange, I call the exact same code for everything and the only case its not working for me is when timescale is 0.
I can clearly see the code being called using breakpoints. Must be something else then. Thanks!