mouse handler for multiple objects

Hello. Help me solve the problem. I have a cube on the scene. I clone them. How and where do I create a script that will create a mouse handler, which when you click on each cube, will return to me exactly the selected primitive.

CreateCube.prototype.initialize = function() {
       var el = this.app.root.findByName('BoxTemplate')
        for(var i = 0; i < 10; i ++){
        var newEl = el.clone()
        newEl.name = 'BoxTemplate'+ i
        newEl.rigidbody.teleport(0,0,5)
        this.app.root.addChild(newEl)
      
//this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, newEl)

    }
};

We have a tutorial on this here: https://developer.playcanvas.com/en/tutorials/entity-picking/

Hopefully that will help :slight_smile:

1 Like

Thanks!