Having trouble getting a click event to run in aframe

156
April 26, 2019, at 4:20 PM

I am trying to write an inventory system for a game using the AFrame library. I have a custom component that is set up to set the item i'm picking up to invisible and turn the in hand item visible. However when ever it runs it won't work.

Currently, i have a click eventlistener set up check when clicked. When clicked it is set to set the target item invisible (el) and the object in hand visible (handObj). It appears as tho the click function isn't evening running as I have a console.log set up to just check if the function ran or not.

var hands = [null, null];
AFRAME.registerComponent('pickUp', {
    schema: {
        handObj: {type: 'selector', default: ''},
        id: {type: 'string', default: ''}
    },
    init: function() {
        var el = this.el;
        var data = this.data;   
        el.addEventListener('click', function() {
            //pickup="target= #right
            console.log("hello");
            if(hands[0] == null) hands[0] = data.id;
            else if (hands[1] == null) hands[1] = data.id;
            else break; 
            el.setAttribute('visible', 'false');
            data.handObj.setAttribute('visible', 'true');
        });
    }
});
 <a-box id="left1"
     color="#AA0000" class="clickable"
     position="8.000 0.200 7" depth = ".25"  height = ".25" width = ".25"
     event-set__enter="_event: mouseenter; material.color: #FF0000"
     event-set__leave="_event: mouseleave; material.color: #AA0000"
     pickUp="handObj: #left2; id: left"
    >

I don't understand why the click function isn't working at all since i have copied the formatting from tutorials and those components work fine.

Rent Charter Buses Company
READ ALSO
Putting dynamic objects in order

Putting dynamic objects in order

Currently, I have a code and is working perfectly! But the output order is wrong, I tried everything to put it in order but I failedCan you help me?

185
How to set the second dropdown box only after the first one is set? [on hold]

How to set the second dropdown box only after the first one is set? [on hold]

I'm working on a project that is using the select2 JqueryI have two drop-down boxes

202
Passing prop to another component and render on the view

Passing prop to another component and render on the view

I have a question about how to pass the props to Form componentRight now, the SideBar component list all the link, and everything I click one of the link, I can console

184
How to modify this JSON to another JSON with JavaScript?

How to modify this JSON to another JSON with JavaScript?

help please, I need to transform this json:

151