#how would i make a textmeshpro text go up by 1 number every click for this?
1 messages · Page 1 of 1 (latest)
Well, you can use an INT variable. Imagine its "volumeLevel"
So you use add (scalar type) node. Connect volumeLevel to input A.
And set volumeLevel to this result.
Then you connect that node output toa " int to string " node and connect that to the text mesh pro node string input
And make sure "this" isnthe GameObject that has this textMeshPro component, or else refer to it via object variable
could you maybe send me an example? i only know the basics of the nodes and dont know c#
its ok if you dont know c#, but you still need to learn how logic flows
when you click, a number adds itself +1.
so if its 5, when you click once it turns to 6.
in code: you get this 5, add 1, and then save it back. so next time, you get it as 6, and add +1 and becomes 7.
so here's the 3 steps that occurs:
the event: when user clicks
the condition: number adds +1 to itself
the result: display that number in the screen
The key here is making a separate, dedicated integer variable to store this increasing value, rather than trying to rely on the current string in the UI text. The UI needs to be thought of as just a presentation layer. The actual logic happens with regular numerical variables, and then we just display a string representation in the UI after the internal logic is done
Here's how i do it in my game. i think this is exactly what you want. please note, i have some things you may not need.
and the nodes i use. im using custom events, that hears from inputManager when the user clicks on that event.
but the logic is this.
each time player clicks, soundVolume current value gets +0.1
why? because volume in game goes from 0 to 1.
it's clamped using Clamp01 which blocks value from going below 0 or above 1.
then it saves that variable with this new value. and set volume to that value.
and then display the value in the text mesh pro element using a multiply node x10
why? because i dont want to show 0.1 or 0.5 volume. i want to display 0 to 10.
and how does the UI element sends the script that this button is being clicked?
well, you have 2 choices. triggerEvent component or in this case i used button component.
you select first the object that is listening to this click, in this case "Options_UI" which is the gameObject that has Unity Event node receiver
and you add a name to this event to be heard, i nthis case "plusSound"