Search Unity

Assign Integer Values to Button Array

Discussion in '2D' started by wraith1821, May 27, 2018.

  1. wraith1821

    wraith1821

    Joined:
    Nov 26, 2017
    Posts:
    30
    Is there a way to assign an integer value based on the Button Text to each UI button in an array and then check for that value OnClick() for valid move based on the value assigned ?

    basically

    Code (CSharp):
    1. for (int i = 0; i < buttons.Length; i++)
    2.         {
    3.             buttons[i].interactable = true;
    4.             buttons[i].GetComponent<Image>().sprite = null;
    5.             // some code here to assign an integer value to each button in the array.  int variable is boardSquareValue;
    6.  
    7.  
    8.         }
    Something like button.Text = int.TryParse(in [some variable] ,out variable); <---- This didnt work obviously.

    I've been stuck on this for days.

    Thanks
     
  2. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Do you know why it doesnt work? Can you post the code you tried? That should work. Works for me.
     
    wraith1821 likes this.
  3. wraith1821

    wraith1821

    Joined:
    Nov 26, 2017
    Posts:
    30
    I figured it out. I forgot I removed the script from some of the buttons *FacePalm*

    One last small tiny issue and this thing will be done codewise. Posted new thread if you don't mind looking. Thank you for the response.