I'm trying to make a raycaster only function when an entity is visible. I was told to try to write a script in order for this to work, so I went ahead and did such. All entities and child entities, I have interactable through click and have most of my events triggered through click, which make certain entities turn invisible as such:
<script id="city" type="text/html">
<a-entity class="city"
geometry="primitive: plane; height: 0.2; width: 0.5"
data-raycastable
material="color: black"
text="value: ${city_name}; color: white; align: center; wrapCount: 10; font: exo2bold"
event-set__mouseenter="scale: 1.5 1.5 1"
event-set__mouseleave="scale: 1 1 1"
event-set__1="_event: click; _target: #image-360; _delay: 300; material.src: ${src}"
event-set__2="_event: click; _target: #models; _delay: 300; visible: false"
event-set__3="_event: click; _target: #cities; _delay: 300; visible: true"
event-set__4="_event: click; _target: #show_button; _delay: 300; visible: true"
event-set__5="_event: click; _target: ${map}; _delay: 300; visible: true"
proxy-event="event: click; to: #image-360; as: fade"
sound="on: click; src: #click-sound"></a-entity>
</script>
The data-raycastable parameter you see here is running of this here script:
AFRAME.registerComponent('data-raycastable', {
init: function () {
var self = this;
var el = this.el;
var data = this.data;
this.eventHandlerFn = function () {
if (el.object3D.visible = true){
el.setAttribute('data-raycastable', '');
}
else {
el.removeAttribute('data-raycastable')
}
}
update: function() {
el.addEventListener('click', this.eventHandlerFn);
}
}
}
})
Now, I'm wondering why this script of mine doesn't work. I followed the A-frame documentation closely in an attempt to make it work, but it doesnt. The cursor button looks like this:
<a-entity id="camera" camera look-controls>
<a-cursor
id="cursor"
material="color: black; shader: flat"
position="0 0 -4.5"
geometry="primitive: ring; radiusInner: 0.15; radiusOuter: 0.2"
animation__click="property: scale; startEvents: click; from: 0.1 0.1 0.1; to: 1 1 1; dur: 150"
animation__fusing="property: fusing; startEvents: fusing; from: 1 1 1; to: 0.1 0.1 0.1; dur: 1500"
event-set__mouseenter="_event: mouseenter; color: springgreen"
event-set__mouseleave="_event: mouseleave; color: black"
raycaster="objects: [data-raycastable], .link, .model">
</a-cursor>
</a-entity>
Can someone please steer me in the right direction.