johnhattan icon

Remotely-clickable Button Component in Unity

johnhattan | PRO | 01/24/17 04:46:50 PM UTC | 0 ⭐ | 381 👁️ | Never ⏰ | []
C# |

320 B

|

None

|

0 👍

/

0 👎

using System.Collections;
 
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
 
public class UIButtonRemote : MonoBehaviour
{
    public void OnClick()
    {
        EventSystem.current.SetSelectedGameObject(gameObject);  // select me
        gameObject.GetComponent<Button>().onClick.Invoke(); // and click me
    }
}

Comments