Hello can anybody tell me how to display variable as text on the screen? I mean something like “Coins picked: (variable)”
Hi @smokys,
You can easily do that with a text UI element and some simple code. Check the UI example projects on how to set this up:
Im trying it and it seem to be complicated, im little bit frustrated but i will try to work with it somehow.
The closest tutorial that will help you is probably this one https://developer.playcanvas.com/en/tutorials/ui-elements-stats-counter/
Where the text element is updated to show a particular value.
An easy way to display a variable in a UI is by doing this:
myscript.prototype.initialize = function(){
this.coinvalue = 0;
}
myscript.prototype.update = function(dt){
var textbox = this.app.root.findByName('TextBoxName');
var value = this.coinvalue;
textbox.element.text = value;
}
This one helped waaaay tooo enough, thank you so much <3
This is one of the really easiest
there is exatcly 99 coins :o
Haha ye, funny is that it is all random
if you want to switch the perspective to 2d just switch this to orthographic ( its under the camera )
myscript.prototype.initialize = function(){
this.coinvalue = 0;
}
myscript.prototype.update = function(dt){
var textbox = this.app.root.findByName('TextBoxName');
var value = this.coinvalue;
textbox.element.text = "Coins Picked:" + value;
}
modified it a bit. it will now show Coins Picked next to the updating value.
Well done, that is what i was looking for