16 February, 2016

AFrame Clickable Entities
By: Matthew Jackson

A-Frame tutorials use "document.querySelector"; however, using document.querySelectorAll, has a bug that doesn't apply. Also if you want to affect newly added objects, querySelector was having issues (Edit: It is working now).

Luckily, we have a workaround to use jQuery.

$("body").on("click","a-entity",function(){
      console.log("Clicked!");
      this.setAttribute('material', 'color', 'red');
});

With the above code you can click on any object as long as it is in the cross hairs.

Tags: AFrame