Access to script from another scene by the main menu
Hi everyone,
First of all I'm a beginner in C# . I 'm working on a project composed of 2 scenes : one for the main menu and the other one for the "game". In my second scene : the "game" , I'm able through the Inspector to control some stuff (like day lenght in minute ...) thanks to sliders. Here's my question : how can I have access to these sliders in my main menu, is there any way to do that ?
Thanks for your help ! :)
Do you want access to those sliders while you edit the scene or while the game plays? I don't really see a reason why this should be possible during the editing.
I would like access to those sliders from my main menu while the game plays. Actually I already created sliders in my main menu but I don't know how they can control those present in the game scene ...
I hope my explanation is clear.
Thanks for your help :)
Please use comments as responses. Answers should be only used as a proposition for a solution.
Answer by Cynikal · Nov 04, 2016 at 10:32 AM
Depending on which slider you used..
Assuming it's the UGUI slider:
using UnityEngine.UI; <-- Necessary
Slider mySlider = GameObject.Find("Slider GameObject Name").GetComponent();
then reference mySlider.
Answer by Zodiarc · Nov 04, 2016 at 10:33 AM
if I understood you correctly there are two ways:
You add this game object to the main menu instead of the game scene and use DontDestroyOnLoad
You add this game object to the main menu. Before you load the game scene you store those values somwhere (PlayerPrefs for example) and in the game scene you load those values and set them as soon as the scene is loaded.
Your answer
Follow this Question
Related Questions
Setting Hierarchical slider parameters via script 0 Answers
Unable to Compile scripts on my game but my Team mates can on their machines?CS0103 0 Answers
How Do I Make A Change A Volume With A Slider? 3 Answers
Problem With Multiple Sliders - Health Bars 1 Answer
How to make it so I can't use the jetpack/jump while slider value is 0? 0 Answers