public void changeListener() { for (int i = 0; i < 4; i++) { if (ButtonUtil.IsActive(buffBtns[i])) { choise = i; } /*else * { * buffBtns[i].gameObject.SetActive(false); * }*/ } Debug.Log("choise " + choise); for (int i = 0; i < 4; i++) { if (i != choise) { Debug.Log("222"); buffBtns[i].gameObject.SetActive(false); } } switch (choise) { case 0: buffBtns[choise].onClick.RemoveAllListeners(); buffBtns[choise].onClick.AddListener(delegate() { character.AddComponent <Magnet>(); destotyItself(); }); break; case 1: buffBtns[choise].onClick.RemoveAllListeners(); buffBtns[choise].onClick.AddListener(delegate() { SpeedUp speedUp = character.AddComponent <SpeedUp>(); Debug.Log("set power: " + speedUpPower); speedUp.power = speedUpPower; destotyItself(); }); break; case 2: buffBtns[choise].onClick.RemoveAllListeners(); buffBtns[choise].onClick.AddListener(delegate() { character.AddComponent <Overbearing>(); destotyItself(); }); break; case 3: buffBtns[choise].onClick.RemoveAllListeners(); buffBtns[choise].onClick.AddListener(delegate() { character.AddComponent <Wingsuit>(); destotyItself(); }); break; } }