using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class NewBehaviourScript : MonoBehaviour {
public static NewBehaviourScript newBe;
public int Num;
static NewBehaviourScript(){//在另外随便一个脚本赋值Num,然后切换场景就会发现这个脚本永远在一个物体上,并不会被销毁
GameObject go = new GameObject ();
DontDestroyOnLoad (go);
newBe = go.AddComponent<NewBehaviourScript> ();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0)) {
LoadSc ();
}
if (Input.GetMouseButton(1)) {
LoadSce ();
}
}
public void LoadSc(){
SceneManager.LoadScene ("Sc2");
}
public void LoadSce(){
SceneManager.LoadScene ("Sc1");
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class NewBehaviourScript : MonoBehaviour {
public static NewBehaviourScript newBe;
public int Num;
static NewBehaviourScript(){//在另外随便一个脚本赋值Num,然后切换场景就会发现这个脚本永远在一个物体上,并不会被销毁
GameObject go = new GameObject ();
DontDestroyOnLoad (go);
newBe = go.AddComponent<NewBehaviourScript> ();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0)) {
LoadSc ();
}
if (Input.GetMouseButton(1)) {
LoadSce ();
}
}
public void LoadSc(){
SceneManager.LoadScene ("Sc2");
}
public void LoadSce(){
SceneManager.LoadScene ("Sc1");
}
}