Unity的Scene之間如何傳遞數(shù)據(jù),成為UP主的第777天留念。
寫一個Static的Singleton的class,數(shù)據(jù)存里面就可以了。別忘了加DontDestroyOnLoad(this.gameObject);
例子:
public class PlayerDataSingleton : MonoBehaviour
{
? ? public static PlayerDataSingleton instance;
? ? public int anyData;
? ? private void Awake()
? ? {
? ? ? ? instance = this;
? ? ? ? DontDestroyOnLoad(this.gameObject);
? ? }
}
標簽: