Search Unity

Need basic help assigning values to dropdown menu

Discussion in 'UGUI & TextMesh Pro' started by matthew77, Jan 13, 2018.

  1. matthew77

    matthew77

    Joined:
    Dec 17, 2016
    Posts:
    29
    Hi. I need some help. I recently started to try and learn buttons and dropdown menus so I can create a HUD (heads up display) button system for a virtual world containing many scenes that I am attempting to build.

    I have created the dropdown menu and a script for changing scenes. The script works to change to the second scene by pressing a button in the dropdown menu. I created another almost identical script to change to a third scene and this is where I am running into a problem. Both options in the dropdown menu currently take me to the same scene when clicked.

    I currently have both options set up in the "on value changed" area.

    How would I go about assigning different scripts to the options in the "values" part of the dropdown menu?

    Can anyone point me in the right direction or tell me what I need to do?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If you want to change scenes from the dropdown, 1 option would be to have the method take an int paramter.Then, you can load the scene based on the integer. Just use the same script :)
    Code (csharp):
    1.  
    2. public void ChangeLevel(int level) {
    3.     int levelToLoad = level + 1; // this could be anything. Maybe 1= 4, 2 = 6, 3 = 8
    4.        // when going from the dropdown to your build index. Or maybe you just need +1 or +2 or maybe
    5.        // you don't need any modification at all :)
    6.     SceneManager.LoadScene(levelToLoad);
    7.    }
    There are surely other ways you could do this. Let me know if this sounds good or not to you =)
     
  3. matthew77

    matthew77

    Joined:
    Dec 17, 2016
    Posts:
    29
    Thanks for the response! I'll give this a try and let you know if it works for me. Thanks again! :)
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Cool :) Hope it works for ya.