Aframe 为什么不是';a型架点击事件是否正常工作?

Aframe 为什么不是';a型架点击事件是否正常工作?,aframe,webvr,Aframe,Webvr,我试图弄清楚为什么我的控制台没有在我的点击事件处理程序中记录我的日志语句。任何帮助都将不胜感激 这是我的JS小提琴 我使用的是A-Frame版本5.0 这是我的HTML <!-- Player --> <a-entity camera universal-controls="movementControls: checkpoint" checkpoint-controls="mode: animate" position="0 1.764 0"&g

我试图弄清楚为什么我的控制台没有在我的点击事件处理程序中记录我的日志语句。任何帮助都将不胜感激

这是我的JS小提琴

我使用的是A-Frame版本5.0

这是我的HTML

 <!-- Player -->
  <a-entity camera universal-controls="movementControls: checkpoint" checkpoint-controls="mode: animate"
            position="0 1.764 0">
    <a-entity cursor="fuse: true; fuseTimeout: 500" position="0 0 -1"
              geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03;" material="color: #CCC; shader: flat;">
    </a-entity>
  </a-entity>


  <a-entity id="box" cursor-listener geometry="primitive: box" material="color: blue" position="-2 2.2 -1.5"></a-entity>

我相信在使用元素之前,您必须确保组件已注册

下面是您的示例的修改版本:


AFRAME.registerComponent('cursor-listener'{
init:函数(){
this.el.addEventListener('click',函数(evt){
log('我被点击在:',evt.detail.intersection.point);
});
}
});
...

这是有道理的。谢谢,我只是将app.js移到了头部,而不是我的工作表底部。非常感谢你的帮助。
$(document).ready(function() {

  AFRAME.registerComponent('cursor-listener', {
    init: function () {
      this.el.addEventListener('click', function (evt) {
        console.log('I was clicked at: ', evt.detail.intersection.point);
      });
    }
  });

  AFRAME.registerComponent('collider-check', {
    dependencies: ['raycaster'],
    init: function () {
      this.el.addEventListener('raycaster-intersected', function () {
        console.log('Player hit something!');
      });
    }
  });

});
<script>
AFRAME.registerComponent('cursor-listener', {
    init: function () {
         this.el.addEventListener('click', function (evt) {
        console.log('I was clicked at: ', evt.detail.intersection.point);
      });
    }
  });
</script>
<body>
...
<a-entity id="box" cursor-listener geometry="primitive: box" material="color: blue" position="-2 2.2 -1.5"></a-entity>