Basicly I’m working on a 2.5 d side scroller and I want to create a ui store, for example the main menu would be…
GAME NAME
Play
Store
Highscore
Exit
And the store menu would contain different player prefabs for example a xmas themed player, which you can buy with coins earned within the game, stuff you cant afford would be greyed out, a buy and equip button and a main menu/return button, for example
There are numerous ways that you could structure this system, so keep in mind this is only one. I would create it as a modular system using multiple scripts, each with a well-defined task, and maybe some sort of hierarchy. In particular, I’d use:
A UI management script that would handle all the UI, including the greying-out and the button clicks
An inventory script that persists throughout the game that tracks the player’s money and items
A lower-level item-equipping script to handle the particulars of changing the player’s appearance
The process would work something like this:
The inventory script tracks the player’s money throughout the game. Once the player enters the store context, the UI management script checks the inventory to get the amount of money, and then generates the store UI appropriately. When the user clicks the “Buy Santa Hat” button, the UI script tells the inventory management script to subtract X amount of dollars and add the Santa Hat to the inventory. The inventory is then aware that the Santa Hat is available to the player, and can tell the item-equipping script to do the work of changing the player’s character to include the Santa Hat.
Using separate scripts like this will allow you to keep your code cleaner and approach each type of problem separately. For instance, you can get the entire buying mechanic functioning without having to worry about the code for changing the player’s appearance.
As for the nitty-gritty of actually writing the scripts, there’s no better way to get improve at it than to practice. If you run into trouble with specifics you can always ask another question, or maybe start a thread on the forum and link it here so there can be some sort of running discussion.