- Home /
item shop menu screen
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
STORE
Xamas hat "pic" 100© equip
Mainmenu.
How would I go about doing this? Where would I begin? I have the main.menu working and a scene with a canvas ready for the store. Thanks in advance
I'm not really sure what your question is. $$anonymous$$ost of the work is just creating the UI for the store, which it seems you know how to do. Other than that, you just need to have some script that tracks things like how much money the player has, whether they have the Christmas hat, etc. and update both the store UI and the player's model, etc. If you can be more specific about what you need help with it would make it easier to come up with a more complete answer. Hope this helps a bit at least though.
I can track the total coins the player has, I'm guessing that the buy buttons will check the amount of coins (be greyed out if theres not enough money) and subtract the amount from the coin total. I just dont know how to; equip the hat after buying, or how to script any of this in a simple way(c#) I could try but it'd be a messy script and I belive there is a simple way to script it
Answer by ZefanS · Dec 11, 2015 at 08:40 AM
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.
Thank you so much for your clear and easy to understand answer this will help me tons! I was going to try and use.one script which would.of.been chaotic, but now I know.where. to start and will give it.a go, again thank you so much for this answer, you've helped me out alot and hopefully others with a similat problem :D
You're welcome! I'd appreciate it if you could hit the Accept button to mark this as the best answer.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Menu in C# 2 Answers
drop down list c# 1 Answer