I have created simple movement buttons in my game. They should trigger functions of the player's scripts, but I can't link the button to the player object/script canonically from the inspector 'cause the player is created at runtime. So I created a custom script attached to the buttons:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ActionButton : MonoBehaviour {
private Button btn;
void Start()
{
btn = GetComponent<Button>();
btn.onClick.AddListener(TriggerFoo);
}
public void TriggerFoo()
{
Debug.Log("Btn triggered!!!!");
}
}
Haven't implemented yet the behavior I want to achieve with it, but even at this point the button doesn't print the string on console.
Here is how the button is set up in the inspector:
I am missing something very obvious here....?