Код: Выделить всё
// The rest of the menu is assembled around this. There is a 'foreach' loop adding the buttons one at a time.
GameObject obj = Instantiate(quickCommandPrefab, FindCorrectHolder(c.cType).transform);
// >>>
// There are other things happening here that aren't having problems.
// >>>
// set the event for the "button press"
btn = obj.transform.GetComponent();
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(delegate { CheckKeyPress(c.keyToActivate); });
// There is just something about the button onClick event.
Это компоненты создаваемого объекта.

Я даже пошел настолько, что можно выделить этот код в отдельную функцию для выполнения отдельно после создания экземпляра следующим образом:
Код: Выделить всё
void SetupButtonEvents()
{
foreach (Button btn in transform.GetComponentsInChildren(true))
{
Button temp = btn; // I did try a temp variable as well to see if that would help. NOPE, same problem!
string keyCode = btn.transform.Find("UseKeyText").GetComponent().text;
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(delegate { CheckKeyPress(Enum.Parse(keyCode)); });
}
}
Я использую Debug.LogWarnings, чтобы отслеживать, что происходит, и btn.onClick.GetPersistentEventCount() всегда возвращает 0.
p>
Я не могу сказать, так как у меня уже была эта проблема раньше, хотя обычно это происходит без собственной системы событий Unity или с использованием указанной системы событий через инспектор, а не через код.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ns-in-code
Мобильная версия