1)通过静态变量传递
可以创建一个静态类,或者类里面有静态变量
2)创建一个不会被销毁的游戏物体
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PersistentData : MonoBehaviour { public static PersistentData thePersistentData; //要保存使用的数据; [NonSerialized] public int index = 0; [NonSerialized] public string ID = "identify"; //初始化 private void Awake() { if (thePersistentData == null) { DontDestroyOnLoad(gameObject); thePersistentData = this; } } // Update is called once per frame void Update () { } }
此方法网上给出的比较多,与第一种一样
3)通过xml或者json来存储
4)少量数据可以用PlayerPref来实现