using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public string LevelToLoad;
private float timer = 10f;
private Text timerSeconds;
// Use this for initialization
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);
}
}
}
This is the code I have but it won't be suitable for my unity 3.1.2
Can someone please tell me what to adjust so the code would fit my unity v3.1.2
CodePudding user response:
As the warning says "Use SceneManager.LoadScene" you should use SceneManager.LoadScene
instead of Application.LoadLevel
. The only difference is that SceneManager.LoadScene
uses indexes of the scenes ordered in Build Settings and Application.LoadLevel
uses a string of the scene name.
Conclusion: Change Application.LoadLevel
to SceneManager.LoadScene
and pass in the index of the scene you want to load.
If you don't have using UnityEngine.SceneManagement
make sure you include that because SceneManager.LoadScene
uses that.