- Home /
 
 
               Question by 
               silvia_secomandi · Aug 06, 2020 at 12:57 PM · 
                c#timeslidercountdown  
              
 
              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;        
  }
 
              
               Comment
              
 
               
              Your answer