局部变量和全局变量的区别
//全局变量定义
//private GameObject left;
//private GameObject right;
//private GameObject manager;
//private GameObject lab;
private Animation leftGateAnim;
private Animation rightGateAnim;
private Animation managerDoorAnim;
private Animation labDoorAnim;
private GameObject gatePoint;
private float ToCameraDistance = 1.4f;
void Start ()
{
gatePoint = GameObject.Find("GatePoint");
//局部变量定义
var leftGate = GameObject.Find("office/LeftGate");
leftGateAnim=leftGate.GetComponent<Animation>();
var rightGate = GameObject.Find("offcie/RightGate");
var managerDoor = GameObject.Find("office/ManagerDoor");
var labDoor = GameObject.Find("office/LabDoor");
}
其中的left、right、manager、lab是全局变量,在本脚本的其他函数中都可以调用,而leftGate、rightGate、managerDoor、labDoor是局部变量,只能在本函数中调用,其他函数不能调用。