在Unity3D中使用全局变量要注意以下几点
1.定义一个Global类,将静态变量写在里面
2.Global中不引用MonoBehaviour对象,除非这个对象被执行过DontDestroyOnLoad否则在切换场景时会变成null
using UnityEngine;
using System.Collections;
public class GlobalMono : MonoBehaviour
{
public static int a = 1985;
public static TestStatic b = new TestStatic();
}
public class Global
{
public static int a = 1983;
public static TestStatic b = new TestStatic();
public static cgame c = null;
}
public class TestStatic
{
int a = 111;
}