注意场景切换的脚本挂载的物体不能摧毁

场景都要放到buildsettings里

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.SceneManagement;
public class changescene : MonoBehaviour
{

public int is_scene1;
public int a=0;
// Start is called before the first frame update
void Start()
{
DontDestroyOnLoad(this); //不摧毁当前物体,不然该脚本只能运行一次,因为切换场景后该脚本挂在原来场景中的物体也没了。
is_scene1 = 1;
}

// Update is called once per frame
void Update()
{ if (Input.GetMouseButtonDown(1))
{

a = a + 1;
print(a);
SceneManager.LoadScene("scene2");     //切换场景的名字
//is_scene1 = 2;

 


}

}
}