This might sound ridiculous but how do i add one to a variable with a keybind.
look at my code
myScript.attributes.add("coinAmount", {type:"entity"});
//this code is in the update function
var x = 0
if(this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT)){
x + 1;
}
this.coinAmount.element.text = x;
It shows 0 on the text but when i press my mouse button it does not increase
and the code that isn’t the attribute is in the update function
You probably want to do something like this instead:
var MyScript = pc.createScript('myScript');
MyScript.attributes.add('coinAmount', { type: 'entity' });
// initialize code called once per entity
MyScript.prototype.initialize = function() {
this.x = 0;
};
// update code called every frame
MyScript.prototype.update = function(dt) {
if (this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT)) {
this.x++;
this.coinAmount.element.text = "" + this.x; // <= This will convert this.x to a string
}
};
myScript.attributes.add("coinAmount", {type:"entity"});
//this code is in the update function
var x = 0
if(this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT)){
x++;
}
this.coinAmount.element.text = x;