- Home /
Access Inventory from player
So guys, I am making a game where when player purchases weapons on store they are added to inventory, and player can choose which weapon to use from Inventory section which is in Main Menu Scene. So I have some functionality to make my player equip the weapons from the game play scene directly, basically I pass the name of the gun as a string to player script on inspector and it has in when the level runs. What I want to do is make the player equip weapon from the Inventory. I thought I would do something with events when click on weapons I would just pass the weapons name to player script but the issue is I cant reference my inventory class from the player class because they are on different scenes.
How could I approach that issue? I tried making the Inventory a singleton but it didnt work, I might have to change how I set things up for the inventory for it to work and Im not sure if it will. if you have any other ideas please let me know. Thanks.
Answer by Llama_w_2Ls · Feb 05, 2021 at 10:36 AM
Is it possible to transition the inventory between scenes? For example, keep it on the player, or set it to DontDestroyOnLoad? Singeltons won't work between scenes, because the script gets destroyed when loading a new scene.
You could try using a base scene by loading scenes asynchronously. I'm not entirely sure how to do this, but you could try here
what do you mean by keep it on the player? Its whole another panel. Do you mean like instantiating it in every scene when the scene loads? Can I do that? how would I go about saving it so every level it updates the content inside of it?
I thought that your player was able to transition between scenes without being destroyed, so you could not destroy the inventory object alongside it.
Your answer
Follow this Question
Related Questions
Can't access singleton's dictionary from another singleton 0 Answers
Singleton Problem 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to set the position of an object in another scene? 1 Answer