首先,说一句,垃圾,真的垃圾。Laya的Runtime一点都不好用,这点用起来跟unity中的标签很像,但是有又区别。
具体官方案例地址:https://ldc2.layabox.com/doc/?nav=zh-js-2-4-1
在零零星星一个月时间入门中,心中一直有一个梗。Laya可以使用getChildByName访问自节点
但是不支持多个节点的嵌套,后边看官方的2D示例项目中发现了,获取组件的另一种方式:Runtime。
首先看下官方是如何使用RunTime的。目的是获取场景中的一个脚本,并对其text属性进行赋值。
第一步,场景的Runme属性赋值一个脚本GameUI.js

第二步,需要控制的控件需要在var中命名(或者叫标签),可以在脚本中访问到

第三步,脚本UI类的基类需要和runtime当前节点的类型一致

第四步,在当前UI类中直接使用控件,已经赋值

最后,在一个场景中,不支持相同的var变量名

网友评论