How to add user interactions?
Changing color with click event
var boxMaterial = new BABYLON.StandardMaterial("material", scene);
boxMaterial.diffuseColor = BABYLON.Color3.Random();
box.material = boxMaterial;box.actionManager = new BABYLON.ActionManager(scene);
box.actionManager.registerAction(new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPickTrigger,
function (evt) {
var sourceBox = evt.meshUnderPointer;
//move the box upright
sourceBox.position.x += 0.1;
sourceBox.position.y += 0.1;
//update the color
boxMaterial.diffuseColor = BABYLON.Color3.Random();
}));Dragging an object
Last updated
Was this helpful?
