Hi all,
Apologies if this is a bit of a noob question, but I’ve looked through the API guide/user manual/tutorials but I’m not getting anywhere.
I’m essentially trying to create an entity through code rather than using the editor but am falling at the first hurdle as I’m not even able to get a box to appear.
I have applied the following code to the ‘Root’ of the project, my console log shows up so the code is definitely running, but no box is there.
var CreateEntity = pc.createScript('createEntity');
// initialize code called once per entity
CreateEntity.prototype.initialize = function() {
console.log("run");
var box = new pc.Entity();
box.addComponent("model", {
type: 'box',
});
box.addComponent("rigidbody", {
type: 'rigidbody',
});
box.addComponent("collision", {
type: 'box',
});
};
// update code called every frame
CreateEntity.prototype.update = function(dt) {
};
Link to project is - https://playcanvas.com/editor/scene/524322
Any help would be greatly appreciated.
Matt