Search Unity

Button Interactions problem

Discussion in '2D' started by MysticFeat, Sep 20, 2017.

  1. MysticFeat

    MysticFeat

    Joined:
    Jun 23, 2017
    Posts:
    12
    Select, Update, Insert, and Delete is tagged as UI
    while Akira, Kiel, Kuro, Helper 1, and Helper 2 is tagged as Buttons

    Here's how it works when either select, or Delete is pressed anything that tagged in UI is disabled or not interactable while Buttons are interactable
    When one of them is pressed the UI is enabled and the Buttons is disabled
    error.png

    The problem is whenever I press select or delete I get this error.
    error1.png

    Here's the code
    Code (CSharp):
    1. bool[] spawns = {true, true, true, false, false};
    2. int count = 1;
    3. private bool cooldown = false;
    4.  
    5. public void select()
    6.     {
    7.         Button[] chars = { GameObject.Find("Akira").GetComponent<UnityEngine.UI.Button>(),
    8.                            GameObject.Find("Kiel").GetComponent<UnityEngine.UI.Button>(),
    9.                            GameObject.Find("Kuro").GetComponent<UnityEngine.UI.Button>(),
    10.                            GameObject.Find("Helper 1").GetComponent<UnityEngine.UI.Button>(),
    11.                            GameObject.Find("Helper 2").GetComponent<UnityEngine.UI.Button>()
    12.                             };
    13.         if (count == 1) {
    14.             count = 2;
    15.             for (int x = 0; x < chars.Length; x++)
    16.             {
    17.                 if (spawns[x] == true)
    18.                 {
    19.                     chars[x].GetComponent<Button>().interactable = true;
    20.                 }
    21.                 else if (spawns[x] == false)
    22.                 {
    23.                     chars[x].GetComponent<Button>().interactable = false;
    24.                 }
    25.             }
    26.             cooldown = false;
    27.         }
    28.     }
    Edit: I tried removing Akira from the equation and it works normally
     
    Last edited: Sep 20, 2017
  2. MysticFeat

    MysticFeat

    Joined:
    Jun 23, 2017
    Posts:
    12
    Update: Deleted the button and copied the other ones and changed it to the recent one and worked