I am new to unity, But I want to make some type of script that will give me the ability to walk up to an object, and display a text saying something like “Press E to open Shop” and then when I press ‘E’ Some type of window opens that allows me to buy certain items.
This will be a bit more work if the shop offers certain functionalities, but here’s how i would implement it:
- place a gameObject around, in front or close to your gameObject. This will be your triggerbox
- disable the MeshRenderer if you do not want the trigger to be seen
- check the ‘Is Trigger’ checkbox on the gameObjects Collider
That’s basically your setup in the scene and the easiest part.
As for the scripting (i’m afraid you have to get into coding yourself for that):
- the player needs a script with MonoBehaviour’s OnTriggerEnter function
- this function checks (i.e.) the tag of the gameObject, this should be done if you use triggers for different actions
- if that trigger was the trigger for the shop, draw a label (or a button) onto the GUI in the OnGUI function and ‘enable’ the piece of code which allows you to open the shop (GUI or a 3D solution, your choice) - many ways to do that
- make your shop work => lots of coding
To make the actual shop work, it depends really.
In the upcoming update for my mobile game, I have a store. Basally when the player buys something it saves that information in bools (such as HasBroughtItemName) and once the game starts it checks these bools and if so it then handles giving the player the items.
The saving is done by a way Unity showed themself ( https://www.youtube.com/watch?v=J6FfcJpbPXE ) so players can’t edit the values easily.
Now, if your doing buying once per round (via COD zombies style), that could be simplified by when a player buys the item it simply replaces their weapon/whatever with that item instead.