1.将公共变量从Inspector视图中隐藏: [HideInInspector]
[HideInInspector] public GameObject player;
2.限定Inspector面板上属性值的范围: [Range(min,max)]
[Range(0f,255f)] public int num;
3.在C++中参数的传递方式有:传值,传址,传引用,在C#中只存在在传值,传引用,其中传引用可由关键字ref和out完成,两者之间的区别在于若用ref方式来传递参数,则该实际参数必须先初始化,而out方式则不需要初始化,out参数也称为输出参数。
void Start () { string str1; OutFun(out str1);//参数可以不用初始化 string str = "hello word"; RefFun(ref str);//参数必须初始化public void OutFun(out string str) { str = "我是OUT参数"; } public void RefFun(ref string str) { str = "我是ref参数"; } }
4.协程(Coroutine):中断当前执行的代码,直到终端指令结束接着执行下面代码。