Jump to content

How to use ExecuteCodeAction


iodizer
 Share

Recommended Posts

Hi, could anyone provide me with a standard example for an ExecuteCodeAction.  I haven't been able to find any examples.  I can verify that the code below doesn't work :)   Part of my problem is that I don't understand what the conditional at the end is for... Thanks!

'''

var makeClickResponse = function(mesh){
                    mesh.actionManager = new BABYLON.ActionManager(scene);
                    mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLeftPickTrigger, function(){console.log("it works! "+mesh.name)}, true));                                                     
                }

'''

Link to comment
Share on other sites

Extracted from http://pixelcodr.com/tutos/plane/plane.html

var onpickAction = new BABYLON.ExecuteCodeAction(
    BABYLON.ActionManager.OnPickTrigger,
    function(evt) {
        if (evt.meshUnderPointer) {
            // Find the clicked mesh
            var meshClicked = evt.meshUnderPointer;
            // Detroy it !
            meshClicked.dispose();
            // Reduce the number of ammo by one
            ship.ammo -= 1;
            // Update the ammo label
            ship.sendEvent();
        }
    },
    condition);

b.actionManager.registerAction(onpickAction);

 

Link to comment
Share on other sites

Thanks a lot guys.  I had no idea about the search the playground feature, that is excellent.  The condition is apparently optional.  For those interested the desired function ended up looking like this

  var makeClickResponse = function(mesh){
                    mesh.actionManager = new BABYLON.ActionManager(scene);
                    mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLeftPickTrigger, function(unit_mesh){
                    console.log("it works! " + unit_mesh.meshUnderPointer.name)})
                    );

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...