Make it count on the screen when an item is acquired

Select your desired GUI you want

Select the desired GUI and put it to scene.


collect-items_gui-deploy Place GUI

Code

Here’s a basic example of how to do it. For an enhanced solution, refer to Example 2 👉🏼

const diamond0 = WORLD.getObject("diamond0");
const diamond1 = WORLD.getObject("diamond1");
const diamond2 = WORLD.getObject("diamond2");
const diamond3 = WORLD.getObject("diamond3");
const diamond4 = WORLD.getObject("diamond4");
 
//intialize gui
const showpoint = GUI.getObject("guiBoardTitle");
let diamondCount = 0;
showpoint.setText(diamondCount);
 
function Start() {
    diamond0.onCollide(PLAYER, () => {
        diamond0.kill();
        diamondCount += 1;
        showpoint.setText(diamondCount);
    });
    diamond1.onCollide(PLAYER, () => {
        diamond1.kill();
        diamondCount += 1;
        showpoint.setText(diamondCount);
    });
    diamond2.onCollide(PLAYER, () => {
        diamond2.kill();
        diamondCount += 1;
        showpoint.setText(diamondCount);
    });
    diamond3.onCollide(PLAYER, () => {
        diamond3.kill();
        diamondCount += 1;
        showpoint.setText(diamondCount);
    });
    diamond4.onCollide(PLAYER, () => {
        diamond4.kill();
        diamondCount += 1;
        showpoint.setText(diamondCount);
    });
}

onCollide() requires the Physics Body to be active in order to function.

snippet_physics-body Physics > Body


collect-items_gui-result

GUI Result

Last updated on