在Unity3D中使用全局变量

来源:互联网 发布:h3c路由器绑定mac地址 编辑:程序博客网 时间:2024/04/27 19:47

在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;}


0 0
原创粉丝点击