Collecting the correct object on click

When a user clicks on a 3D object, we need to first check whether the clicked object is an answer object. If it is, this object will be collected and hidden from view, and a list of collected objects will be updated along with the total number to keep track of the user's progress in the game.

To check whether the clicked VR object is an answerObject, we will use the indexOf method to find a match in the answerObjects array, as shown in the following code:

let match = this.state.game.answerObjects.indexOf(vrObject) 

If the vrObject is an answerObject, indexOf will return the array index of the matched object; otherwise, it will return -1 if no match is found.

To keep track of collected objects in the ...

Get Full-Stack React Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.