提问人:Iceigloopenguin Plays 提问时间:8/14/2022 更新时间:8/15/2022 访问量:484
Unity 警告 CS0618:“Application.LoadLevel(string)”已过时:“使用 SceneManager.LoadScene”
Unity warning CS0618: 'Application.LoadLevel(string)' is obsolete: 'Use SceneManager.LoadScene'
问:
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);
}
}
}
这是我拥有的代码,但它不适合我的unity 3.1.2
有人可以告诉我要调整什么才能使代码适合我的unity v3.1.2吗
答:
0赞
Ariel Developer
8/15/2022
#1
正如警告所说,“使用 SceneManager.LoadScene”,您应该使用而不是 .唯一的区别是,它使用在“生成设置”中排序的场景的索引,并使用场景名称的字符串。SceneManager.LoadScene
Application.LoadLevel
SceneManager.LoadScene
Application.LoadLevel
结论:更改并传入要加载的场景的索引。Application.LoadLevel
SceneManager.LoadScene
如果没有,请确保包含它,因为使用它。using UnityEngine.SceneManagement
SceneManager.LoadScene
评论