xlua-C#访问lua中的全局变量

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
/*
 * Author:W
 * C#访问Lua中全局变量
 */
public class CSharpCallLua : MonoBehaviour {

	private LuaEnv luaEnv;
	// Use this for initialization
	void Start () {
		luaEnv = new LuaEnv();

		luaEnv.DoString("require 'CSharpCallLua'");

		//C#访问lua的全局变量
		int a = luaEnv.Global.Get<int>("a");
		Debug.Log(a);
		float b = luaEnv.Global.Get<float>("b");
		Debug.Log(b);
		string c = luaEnv.Global.Get<string>("c");
		Debug.Log(c);
		bool isCheck = luaEnv.Global.Get<bool>("isCheck");
		Debug.Log(isCheck);



	}

	private void OnDestroy()
	{
		if (luaEnv != null)
			luaEnv.Dispose();
	}
}

lua脚本

a=50
b=100.5
c="W"
isCheck = false

运行结果截图如下:
xlua-C#访问lua中的全局变量_第1张图片

你可能感兴趣的:(Unity,xlua)