新建button,然后绑上脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Events;
public class ClickBuTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject btnobj = GameObject.Find("Canvas/Button");
Button btn = (Button)btnobj.GetComponent<Button>();
btn.onClick.AddListener(onclick);
}
void onclick()
{
Debug.Log("Test!");
}
// Update is called once per frame
void Update()
{
}
}