So I have a strange question. I am absolute beginner and I may be misunderstandign things but this is timer code I use:
public class BasicTimer : MonoBehaviour
{
public float timeRemaining = 10;
public bool timerIsRunning = false;
void Start()
{
// Starts the timer automatically
timerIsRunning = true;
}
void Update()
{
if (timerIsRunning)
{
if (timeRemaining > 0)
{
timeRemaining -= Time.unscaledDeltaTime;
Debug.Log(timeRemaining);
}
else
{
Debug.Log("Time has run out!");
timeRemaining = 0;
timerIsRunning = false;
}
}
}
}
All seems fine and dandy… however when I click play in editor, the value doesn’t start at 10 but 4 less (yes, I have checked inspector). If I however make it so player has to click left mouse button in the update, it starts at correct value.
The reason I use “unscaledDeltaTime” is because my game is sped up slightly in project settings to 1.3 Time Scale (it is required).
Any reason why timer is off by 4 seconds on Start() and Awake()?