Gem collection system

how would i do a coin collection system? i want it to be so that when the player walks over the gem, it dissapear’s and the value of it goes to a UI text on the screen. link to project: https://playcanvas.com/editor/scene/1311243

This game does exactly that :
https://playcanvas.com/project/4763/overview/swooop
You might find what you need there :slight_smile:

3 Likes

thanks

it is not working. what script am i supposed to use?

Well this is a full game (not mine, I don’t know anything about it except that it’s nice and cool :slight_smile: )
So you won’t find something to purely copy/paste.

But a quick look in the code can give some hints, such as this in “collectible.js” :

Collectible.prototype.onContact = function () {
    this.entity.enabled = false;
    game.fire('pickup', this);

    //regeneration logic
};

Looks like a contact event is used to trigger a “pickup” and make the collectible disappear.


and then in “game.js” :

Game.prototype.onPickedCollectible = function (collectible) {
    var points = collectible.points;

    // [...]

    this.setScore(this.score + points);
};

Here you can see that a collectible has a “points” attribute, which is used for the score calculation.

One of the collectible’s attributes :
image

1 Like

k
i will try it out