getComponent获取多个BoxCollider组件

由于节点上有多个BoxCollider组件 ,getComponent(cc.BoxCollider)只能获取第一个。没查看到相关api,求解

//按钮变灰
setCellShader:function(index,boole){
    var itemCells = this.allItemCell[index]
    for(var i in itemCells){
        if(itemCells[i].getComponent(cc.Button)){
            itemCells[i].getComponent(cc.Button).interactable = boole
        }
    }
},

类似

不一样吧,你这个是一个node只有一个button组件吧。。我想获得同一node上同名的多个组件。。。。

你创一个数组的节点,将需要用的节点添加在数组节点里,都拉进去,用个这个数组节点for in 取到这个控件就好了

getComponents(cc.BoxCollider)

是这个吧? 有个s的 返回这个节点上 所有同类型的组件

1赞

哟西,就是这个