ulua介绍和使用2

在这里插入图片描述
在这里插入图片描述
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);
    }

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
创建cubeCreat.lua.text文件

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);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值