Hi guys.
I’m trying to create a place object system on PlayCanvas where the player will have an inventory with a bunch of items and can place it on the floor, like The Sims. It’s working fine with a box, but I can’t work with an entity.
First, I created a store script that receives a json formats with some entities:
StoreController.attributes.add('data', {
type: 'json',
array: true,
schema:[{
name: 'item',
type: 'entity'
}, {
name: 'price',
type: 'number',
default: 10
}]
});
And I linked some entities. These one are them for test:
And then when you click on it, you buy them.
Second, I created an inventory that takes these items and lists them and when you click on it, you can place it on the floor. But the problem is on bellow:
PlaceObject.prototype.startPlacing = function(item) {
console.log(item)
this.isPlacing = true;
this.currentItem = new pc.Entity();
this.currentItem.addComponent("render", {
type: 'asset',
asset: item.render.meshInstances[0]
});
this.app.root.addChild(this.currentItem);
};
When I test the code with the ‘BOX’ type the script works very well, but when I tried to render a mesh that I received in ‘item’, it doesn’t work anymore.
What I get in ‘item’ is an entity.
I’ve tried to use ‘item.render’, ‘item.render.meshInstances[0]’, ‘item.render.meshInstances’, ‘item.resouce’, ‘item.model’ but none of them worked, the mesh doesn’t render in the scene…
This is the project:
Overview | Dashboard | Habbo | PlayCanvas | 3D HTML5 & WebGL Game Engine
Could anyone help me?