- Home /
Slider to modify a countdown time in another scene
Hi there! I'm pretty new to this and I am developing a simple game of few scenes. In the first there are the instructions, while in the second there is the actual game (in which a task needs to be carried out within a certain amount of time, otherwise it opens the game over scene). In the instructions scene I decided to create a slider to be able to adjust the countdown time. Here, there is how I modified the slider (image), while below there is the code of the script (TimerChangeScene). using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class TimerChangeScene : MonoBehaviour { public string levelToLoad; public float timer; private Text timerSeconds;
// Start is called before the first frame update
void Start()
{
timerSeconds = GetComponent<Text>();
}
// Update is called once per frame
void Update ()
{
timer -= Time.deltaTime;
timerSeconds.text = timer.ToString("f2");
if (timer <= 0)
{
Application.LoadLevel(levelToLoad);
}
}
public void AdjustTimer (float newTimer)
{
timer = newTimer;
}
Your answer
Follow this Question
Related Questions
Slider to modify a countdown time in another scene ? 1 Answer
Slider to modify a countdown time in another scene 0 Answers
countdown to persist through scenes 2 Answers
Multiple Cars not working 1 Answer
Timer doesn't work properly 2 Answers