C#建立cube
void Start()
{
CreatCube();
}
private void CreatCube()
{
GameObject item= Resources.Load<GameObject>("cube");
GameObject cube=GameObject.Instantiate(item);
cube.transform.localPosition=Vector3.zero;
}
WrapFile添加
_GT(typeof(Resources)),
lua生成一個cube
private string cmd = @"
luanet.load_assembly('UnityEngine')--加載命名空間
Resources=UnityEngine.Resources
GameObject=UnityEngine.GameObject
local 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<GameObject>("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.Resources
GameObject=UnityEngine.GameObject
Vector3=UnityEngine.Vector3
Quaternion=UnityEngine.Quaternion
local cube=Resources.Load('cube')
for i=0, 9,1 do
for j=0, 9,1 do
local player=GameObject.Instantiate(cube,Vector3(i,j,0),Quaternion.identity)
end
end
";
void Start()
{
LuaScriptMgr lua=new LuaScriptMgr();
lua.Start();
lua.DoString(cmd1);
}
luanet.load_assembly('UnityEngine')
Resources=UnityEngine.Resources
GameObject=UnityEngine.GameObject
Vector3=UnityEngine.Vector3
Quaternion=UnityEngine.Quaternion
local cube=Resources.Load('cube')
for i=0, 9,1 do
for j=0, 9,1 do
local player=GameObject.Instantiate(cube,Vector3(i,j,0),Quaternion.identity)
player.name=i..j..'cube'
end
end
void Start()
{
LuaScriptMgr lua=new LuaScriptMgr();
lua.Start();
TextAsset text=Resources.Load<TextAsset>("cubeCreat.lua");
lua.DoString(text.text);
}