本文共 2006 字,大约阅读时间需要 6 分钟。
C#创建cubevoid Start() { CreatCube(); } private void CreatCube() { GameObject item= Resources.LoadWrapFile添加("cube"); GameObject cube=GameObject.Instantiate(item); cube.transform.localPosition=Vector3.zero; }
_GT(typeof(Resources)),
lua生成一个cube
private string cmd = @"luanet.load_assembly('UnityEngine')--加载命名空间Resources=UnityEngine.ResourcesGameObject=UnityEngine.GameObjectlocal cube=Resources.Load('cube')local player=GameObject.Instantiate(cube)player.name=[[cubeplayer]]"; void Start() { LuaScriptMgr lua=new LuaScriptMgr(); lua.Start(); lua.DoString(cmd); }
C#生成
void CreatCube() { GameObject item=Resources.Load("cube"); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Instantiate(item, new Vector3(i,j,0),Quaternion.identity); } } }
lua生成
添加重新生成wrap
_GT(typeof(Vector3)), _GT(typeof(Quaternion)),
private string cmd1 = @"luanet.load_assembly('UnityEngine')--加载命名空间Resources=UnityEngine.ResourcesGameObject=UnityEngine.GameObjectVector3=UnityEngine.Vector3Quaternion=UnityEngine.Quaternionlocal cube=Resources.Load('cube')for i=0, 9,1 dofor j=0, 9,1 dolocal player=GameObject.Instantiate(cube,Vector3(i,j,0),Quaternion.identity)endend"; void Start() { LuaScriptMgr lua=new LuaScriptMgr(); lua.Start(); lua.DoString(cmd1); }创建cubeCreat.lua.text文件
luanet.load_assembly('UnityEngine')Resources=UnityEngine.ResourcesGameObject=UnityEngine.GameObjectVector3=UnityEngine.Vector3Quaternion=UnityEngine.Quaternionlocal cube=Resources.Load('cube')for i=0, 9,1 dofor j=0, 9,1 dolocal player=GameObject.Instantiate(cube,Vector3(i,j,0),Quaternion.identity)player.name=i..j..'cube'endend
加载文件
void Start() { LuaScriptMgr lua=new LuaScriptMgr(); lua.Start(); TextAsset text=Resources.Load("cubeCreat.lua"); lua.DoString(text.text); }
转载地址:http://szrxo.baihongyu.com/