Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How can I access the value of a dropdown in a script that is in a different scene?

Discussion in 'Scripting' started by ArcaneWarrior13, Feb 6, 2022.

  1. ArcaneWarrior13

    ArcaneWarrior13

    Joined:
    Apr 30, 2020
    Posts:
    8
    I have a difficulty dropdown in my main menu and want to access it in the actual game. I can provide more info if needed.
     
  2. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    You have several options for that, you could store its value in:
    • A static variable
    • A scriptable object
    • A manager GameObject marked as DontDestroyOnLoad
    • A value using UserPrefs
    • ...
     
  3. ArcaneWarrior13

    ArcaneWarrior13

    Joined:
    Apr 30, 2020
    Posts:
    8
    Thanks for the response. Of these 4, which one is the best? Additionally, could you elaborate on the one that is the best? Thanks, and sorry for being such a noob.

    Edit: I got it, thanks for the suggestion. I used PlayerPrefs.
     
    Last edited: Feb 6, 2022
  4. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    I guess using UserPrefs is more appropriate for your case, if you want the chosen difficulty to be saved, so that the player does not have to set it every time the game starts.