Button Toggle for Idle game!

I am making a game inspired by Melvor (Runescape inspired idle game). The difference about this game compared to other idle games is that the skill leveling is togglable. When you click on one skill, it only gains items from that skill every time a progress bar reaches the end. The skill “timer” starts over every time you gain xp/item until you toggle the skill off or select a different skill.

Toggle.isOn → timer starts → timer reaches end → gain xp/item → timer starts over

I cannot for the life of me figure out how to make this toggle system for skills. Should I use the UI buttons or should I use a game object? Any sort of help would be great!

That is just a chain of things, each of which is quite simple.

Toggle: make it control a boolean of your own choosing, in an instance your “skills” class. Any tutorial on using Unity toggles would show you this.

Timer starts: set a float variable to zero

Timer runs: add Time.deltaTime to it each time

Timer reaches end: compare float timer variable to limit

gain xp/item: increment something by some amount

Go back to the beginning of the above stack.

Which part are you having difficulty with?

Thank you for replying! The one thing I’m struggling with is deciding whether I should use a toggle or if I should use a button and make it operate as a toggle.

That’s just a game design choice. It’s still only going to be flipping a boolean, nothing else.

In my Datasacks package, this script interoperates a boolean with a UI.Toggle:

https://github.com/kurtdekker/datasacks/blob/master/datasacks/Assets/Datasack/Input/DSUserIntentToggle.cs

And this script interoperates a boolean with a UI.Button:

https://github.com/kurtdekker/datasacks/blob/master/datasacks/Assets/Datasack/Input/DSButtonIncrement.cs

It is called “increment” but if the limit is 2, it flips between 0 and 1, which is False and True, just a boolean.

To visualize the state of the boolean on the actual button, you can use this outputter:

https://github.com/kurtdekker/datasacks/blob/master/datasacks/Assets/Datasack/Control/DSColorizeLookupTable.cs

If you clone that entire project, it has examples of how to use most objects.

Datasacks is presently hosted at these locations:

https://bitbucket.org/kurtdekker/datasacks