在收集完所有硬币后加载一个新关卡

本文关键字:新关卡 一个 加载 硬币 | 更新日期: 2023-09-27 17:54:23

我使用硬币作为游戏对象。我正在使用此代码收集所有硬币并加载新场景,但我无法这样做。

public int score;// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}

void OnTriggerEnter(Collider col){
    if (col.gameObject.tag == "coin1"|| col.gameObject.tag=="Finish") {
    score +=1;
        AudioSource.PlayClipAtPoint(CC, transform.position);
        DestroyObject(col.gameObject);
        addScore();
    }

}
void addScore(){
    score++; 
    if( score == 2 )
    { 
        Application.LoadLevel(1); 
    }}

在收集完所有硬币后加载一个新关卡

在编写该函数时,您应该看到关于该行的警告。它声明Application.LoadLevel()已被弃用(=obsolete)。

相反,你应该使用SceneManager.LoadScene().