unity使用ulua开发只需要实例化一个luastate吗?
之前在网上看到有人在找unity使用ulua开发只需要实例化一个LuaState吗。看到以后我也很好奇,所以也搜了一下,想要知道这个答案,首先先看一下ulua的一些案例,我们就知道答案了。
1、HelloWorldusing LuaInterface;public class HelloWorld : MonoBehaviour {void Start () {LuaState l = new LuaState();// 在C#下使用Lual.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#下使用Luavoid Start () {LuaState l = new LuaState();l.DoString(script); //执行Lua脚本}}
- 相关评论
- 我要评论
-