unity ulua
- 作者: 球迷迷
- 来源: 51数据库
- 2020-10-04
之前在网上看到有人在找unity使用ulua开发只需要实例化一个LuaState吗。看到以后我也很好奇,所以也搜了一下,想要知道这个答案,首先先看一下ulua的一些案例,我们就知道答案了。
1、HelloWorld
using LuaInterface;
public class HelloWorld : MonoBehaviour {
void Start () {
LuaState l = new LuaState();
// 在C#下使用Lua
l.DoString("print('hello world 世界')");
}
}
2、CreateGameObject
using LuaInterface;
public class CreateGameObject : MonoBehaviour {
//Lua脚本 Lua下使用c#
private string script = @"
luanet.load_assembly('UnityEngine') //首先需要加载一个assembly包含指定类型
GameObject = luanet.import_type('UnityEngine.GameObject')//来获得指定类型引用
//使用引用
local newGameObj = GameObject('NewObj')
newGameObj:AddComponent('ParticleSystem')
";
// 在C#下使用Lua
void Start () {
LuaState l = new LuaState();
l.DoString(script); //执行Lua脚本
}
}
不用
1、HelloWorld
using LuaInterface;
public class HelloWorld : MonoBehaviour {
void Start () {
LuaState l = new LuaState();
// 在C#下使用Lua
l.DoString("print('hello world 世界')");
}
}
2、CreateGameObject
using LuaInterface;
public class CreateGameObject : MonoBehaviour {
//Lua脚本 Lua下使用c#
private string script = @"
luanet.load_assembly('UnityEngine') //首先需要加载一个assembly包含指定类型
GameObject = luanet.import_type('UnityEngine.GameObject')//来获得指定类型引用
//使用引用
local newGameObj = GameObject('NewObj')
newGameObj:AddComponent('ParticleSystem')
";
// 在C#下使用Lua
void Start () {
LuaState l = new LuaState();
l.DoString(script); //执行Lua脚本
}
}
不用
推荐阅读
