本文共 1104 字,大约阅读时间需要 3 分钟。
void Start() { LuaState luaState=new LuaState(); luaState.DoString("print(233)"); }
lua代码创建物体
using LuaInterface;using UnityEngine;using UnityEngine.Experimental.UIElements;public class LuaForUnity : MonoBehaviour{ private string str = @"luanet.load_assembly('UnityEngine')--加载命名空间local gameObject=luanet.import_type('UnityEngine.GameObject')--加载命名空间下的类BoxCollider=luanet.import_type('UnityEngine.BoxCollider')local player=gameObject('新物体') --实例化player:AddComponent(luanet.ctype(BoxCollider)) --添加碰撞器"; void Start() { //创建解析器 LuaState luaState=new LuaState(); luaState.DoString(str); }}lua代码创建物体wrap方式
包装新的wrap脚本
WrapFile_GT(typeof(Animator)),
private string str1 = @"luanet.load_assembly('UnityEngine')GameObject=UnityEngine.GameObjectBoxCollider=UnityEngine.BoxColliderAnimator=UnityEngine.Animatorlocal player=GameObject('新物体') --实例化player:AddComponent(BoxCollider.GetClassType()) player:AddComponent(Animator.GetClassType()) "; void Start() { LuaScriptMgr lua=new LuaScriptMgr(); lua.Start(); lua.DoString(str1); }
转载地址:http://izrxo.baihongyu.com/