using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
[SerializeField]
private Button button;
void Start()
{
button.onClick.AddListener(RunThisTask);
}
void RunThisTask(){
//do something
}
}
GetComponent<Button>().onClick.AddListener(()=>print("clicked"));
using UnityEngine;
using System.Collections;
public class Click : MonoBehaviour {
public GameObject gameObjectToClick;
void OnClick(){
gameObjectToClick.SpecialFunction(); //call special function you wanted to call
}
}