概要
ExecuteEvents.Execute
関数を使用することで
スクリプトから uGUI のボタンを押すことができます
using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class Example : MonoBehaviour { public Button target; private void Start() { target.onClick.AddListener( () => Debug.Log( "ピカチュウ" ) ); } private void Update() { if ( Input.GetKeyDown( KeyCode.Z ) ) { ExecuteEvents.Execute ( target : target.gameObject, eventData : new PointerEventData( EventSystem.current ), functor : ExecuteEvents.pointerClickHandler ); } } }