如何设置A框架的按钮输入



我目前正在尝试从Oculus Touch按钮获取按钮输入。我能够将激光控件连接到控件,但我希望能够打开和关闭激光。不确定这是否可能,但我目前正在使用此设置,但没有产生任何响应:

<script>
AFRAME.registerComponent('x-button-listener', {
    init: function() {
        var el = this.el;
        el.addEventListener('xbuttondown', function(evt) {
            var cameraEl = document.querySelector('#cameraRig[#left-hand]');
            cameraEl.removeAttribute('laser-controls');
        });
     }
 });
</script>

<a-entity id="cameraRig">
    <a-entity x-button-listener id="left-hand" teleport-controls="button: trigger; collision-entities: #ground" laser-controls="hand: left"></a-entity>
</a-entity>

任何帮助将不胜感激。

您的查询看起来很奇怪。你不是说

document.querySelector('#left-hand')

document.querySelector('#cameraRig > #left-hand')

(有关更多信息,请参阅 MDN)

你想做.setAttribute('raycaster', 'showLine', false),而不是删除laser-controls

最新更新