ToLua lua中使用GameObject
private string luaString = @"
	
	local GameObject = UnityEngine.GameObject --获取类
	local ParticleSystem = UnityEngine.ParticleSystem; --粒子组件

	
	go = GameObject('go') --创建游戏物体
	go:AddComponent(typeof(ParticleSystem)) --添加组件
	local trsn = go.transform  --获取Transform组件
	trsn.position = Vector3.one  --赋值属性
	
	GameObject.Destroy(go,2)  --2秒后移除物体

";

private LuaState lua;

// Use this for initialization
void Start () {
	lua = new LuaState ();
	lua.Start ();
	lua.LogGC = true;
	LuaBinder.Bind (lua);
	lua.DoString (luaString);
}

void Update ()
{
	lua.CheckTop ();
	lua.Collect ();//专业回收垃圾
}

void Destroy(){
	lua.Dispose ();
}


Update中的lua.Collect(),如果没有了它,lua代码中Destroy了也没有效果


首页 我的博客
粤ICP备17103704号