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. Dismiss Notice

How do I refer to value retrieved from a dropdown menu?

Discussion in 'Scripting' started by aceace012, Jun 1, 2016.

  1. aceace012

    aceace012

    Joined:
    May 29, 2016
    Posts:
    33
    Thanks in advance, mates.
    I know I can use GameObject.Find()getcomponent<>(). = refer to a value in a gameobject..
    But it seems that didn't work with dropdown??

    I can see value changed from 0 to 1 to 2 when option1,2,3 is selected respectively, but I don't know how to refer to this value...

    Can anyone please help? I am using C#.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. aceace012

    aceace012

    Joined:
    May 29, 2016
    Posts:
    33
    Yes..I have read these from script doc ..But I still don't know how can I retrieve that option value (an integer) , and refer to it in other script as an event trigger to trigger some function.

    I have browse through the web, and I am testing with addlistener/ sendmessage/ delegate

    But If someone can give be some direction will offer me so much help..
     
    Last edited: Jun 1, 2016
  4. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Code (CSharp):
    1. using UnityEngine.UI;
    2.  
    3. public Dropdown dd;
    4.  
    5. void Update()
    6. {
    7.     if(dd.value == someValue)
    8.     {
    9.         //Do something here!
    10.     }
    11. }
    12.  
     
    Tore23 likes this.
  5. aceace012

    aceace012

    Joined:
    May 29, 2016
    Posts:
    33
    I am trying to kick my own dump a** ...
    how come I try so long and don't figure out this........

    thx mate,
    SO I will just have to find a way to use this int to call some function then..THX!!
     
    TaleOf4Gamers likes this.
  6. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Here is the tutorial that will show you how to use Unity UI dropdown and Get its value
     
  7. Adastour

    Adastour

    Joined:
    Jan 6, 2021
    Posts:
    48
    Here you add this to your code

    public TMP_Dropdown GameType_DropDown;
    public string GameType_DropDown_Txt;
    public int GameType_DropDown_Int;

    string[] genres = {"RPG", "Adventure", "Simulation", "Puzzel", "Quest", "FPS Shooter", "3rd Person Shooter", "Other", "Turn Based Combat", "Melee Combat", "Fantasy"};


    GameType_DropDown_Int = GameType_DropDown.value;
    for (int i = 0; GameType_DropDown_Int >= i; i++)
    {
    GameType_DropDown_Txt = genres;