版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NippyLi/article/details/79394163
c#脚本还是上一篇文章中的脚本,绑定到Button按钮上
//在unity上拖入对应的输入组件,添加引用对象到lua脚本中
foreach (var injection in injections)
{
scriptEnv.Set(injection.name, injection.value);
}
function start()
print("lua start...")
--添加事件到button上 打印输入的内容
--self:GetComponent("Button").onClick:AddListener(function()
--print("clicked, you input is '" ..input:GetComponent("InputField").text .."'")
--end)
--添加事件到button上 给输入框赋值
self:GetComponent("Button").onClick:AddListener(function()
input:GetComponent("InputField").text = "hello world"
end)
end
**–1获得组件
–self:GetComponent(“Button”)
–2.给lua脚本传参数
–Inspector面板有个 Injections 设置Size 绑定对应的控件 在lua中可以根据名字调用组件**