I want to make a script that hides the cursor if LMB is pressed.
Here is the code: (it isn’t attached to any entity)
var Mouse = pc.createScript('mouse');
// initialize code called once per entity
Mouse.prototype.initialize = function() {
this.app.mouse.enablePointerLock();
};
// update code called every frame
Mouse.prototype.update = function(dt) {
this.mouseCheck();
};
Mouse.prototype.mouseCheck = function(event){
if(event.button === pc.MOUSEBUTTON_LEFT){
this.app.mouse.enablePointerLock();
}
};
The problem is that the right mouse button triggers the pc.MOUSEBUTTON_LEFT
event button. The same goes for the pc.MOUSEBUTTON_MIDDLE
event button.