- Home /
How to change variables from a script in another scene?
So basically the problem I'm having is this: I'm making an FPS, and the script I have to pick up weapons uses the boolean "beingHeld", its set to true in the inspector for the weapon which is being actually held. The problem is, I'm making a menu with the GUI in Unity and want specific weapons according to the GUI button that is pressed, to be beingHeld = true in the inspector, but since its another scene, I can't access the game objects, I can access the script, but all the other weapons would be set to beingHeld = true, but I only want the specific weapon to be set to true in the inspector, if this button has been pressed. Anyone know how to do this?
Answer by fafase · Oct 14, 2013 at 05:19 AM
Use a static class with static member for your inventory.
The static class is not destroyed at the end of a scene so its members are kept with their values.
You could also use an object with DontDestroyOnLoad.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Why are variables assigned through the inspector considered not assigned when prefab is spawned? 1 Answer
passing variables through scripts 0 Answers
What is the best way to store data about a GameObject? 1 Answer
A variable im trying to pull from another script is reseting when it shouldn't? 0 Answers