Search Unity

Problem Passing Values through UI

Discussion in 'UGUI & TextMesh Pro' started by Homicide, Feb 16, 2018.

  1. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Hi guys. I need some help figuring out something that is just baffling me, ty

    helpme01.png

    i have tried multiple UI controls, inputField, drop down menu... and none are working the way i thought they should, even after watching a tutorial showing it clearly working. i figure i must be overlooking something very obvious.

    the hi lited red value, if changed during runtime, DOES change the value im trying to change, but during runtime, changing the drop down menu from 2, to 4, or 8 does nothing and the value remains 0 always.

    this function is in my A3DManager...

    Code (CSharp):
    1.     public void SetXLength(int x)
    2.     {
    3.         cellXLength = x;
    4.     }
    in the tutorial video i watched, that hilited value field with the 0 wasnt even there.... so im really confused. i tried inputField before DropDown. No luck either of them. :(

     
    Last edited: Feb 16, 2018
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If you want the method to take the value of the dropdown, make sure you choose the dynamic method option in the list. It will be at the top, and won't have an integer field for you to fill in.

    Then, as for getting the right data assigned... You could create an array or list that matches, something like {2, 4, 8), or you could try something like this:
    Code (csharp):
    1.  
    2. [SerializeField]
    3. int myint = 0;
    4. [SerializeField]
    5. Dropdown dropDown;
    6. List<Dropdown.OptionData> optionData;
    7.  
    8. public void Something(int i)
    9. {
    10.    if (optionData == null)
    11.       optionData = dropDown.options;
    12.    myint = int.Parse(optionData[i].text);
    13. }
    Obviously you can replace 'myint' with your proper assignment :)
    If option data doesn't ever change, and is available at the time this script's 'Start' would be called, it would be better to move the assignment to that method, I think. This was just a quick bit of code to help you out :)
    This code could be modified a little bit if the optiondata changes at runtime.