1
同时学习Aframe/Javascript。了解组件
试图写我自己的组件,它改变对象的半径2点击,但如果如果对象的半径已经是2,那么它应该减少半径1
我将如何引用球体对象,我试图改变组件的半径。
谢谢
这是我的组件逻辑。
AFRAME.registerComponent('change-radius', {
schema: {
radius: {type: 'int'}
},
init: function(){
var data = this.data;
this.el.addEventListener('click',
function(){
if (data.radius === 1) {
this.setAttribute('radius', data.radius);
console.log('THIS ONE');
} else {
this.setAttribute('radius', 1);
console.log('NO !!!! THIS ONE');
}
})
}
});
这是我的球体代码。
<a-sphere id="sphere" change-radius="radius: 2" change-color="color: #0000FF" color="#F44336" radius="1" position="0 2 -4"></a-sphere>