var Coin = pc.createScript('coin');
Coin.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onCollision, this);
};
Coin.prototype.onCollision = function(event) {
console.log(event);
this.app.fire('Overlay:CoinCount');
this.entity.destroy();
};
Hi @lowprioismylife and welcome! If you mean you want to add a new coin to your scene, you can create a template for you coin and instantiate this template.
this is my game that I created and I’m just new
I just want my coins to respawn again after I collected it
Is there any solution to this?
Thanks in advance
https://playcanvas.com/editor/scene/1417998
First of all, if you want to keep the coin in the game you don’t want to destroy the entity, like you do right now. I’m not sure what you mean with respawn in this case. Do you want to change the position of the coin, if the coin is collected?
Yes please
You could also try disabling the coin and having some kind of a master script to reneable it after a certain amount of time. I did this at one point.
You need a reference for your new position first. That can be the position of an entity in your scene or a position that you create by script. Then you can set the position of your coin.
var newPosition = this.app.root.findByName('NameOfEntity').getPosition();
this.entity.setPosition(newPosition);
var newPosition = new pc.Vec3(0, 0, 0);
this.entity.setPosition(newPosition);
This really helps. Thank you so much sir
Sir I still have a problem, can you please check this
https://launch.playcanvas.com/1417998?debug=true
Can I see your game?
No need to call me ‘sir’, but what is the problem?
After I collected the coin 4 times, it does not reach my player anymore because of the script in my platform movement
try making some clones of the coins
I see you solved the issue already. Well done!