cancel
Showing results for 
Search instead for 
Did you mean: 

Making buttons react to MouseClicks as well as Poke/Ray cast

0ctipusPrime
Explorer

Hello, I am trying to make buttons react to both poking and mouse clicks in Play Mode in Unity. I got poking working through prefabs, but am struggling to add the functionality where they are triggered by mouse clicks as well. Has anyone done this? 

The reason is so that I speed up development on Mac since currently I have to build the program, put on headset, test it, attempt to fix issues, repeat. Each round taking way too long. 

Thank you for your help. 

2 REPLIES 2

KoanDev2
Honored Guest

Found the Solution? I have the exact same issue. 

Hi, yes, I ended up adding the normal Unity Button functionality onto the meta prefab. I implemented it as custom script (below) on the Button Panel game object (under Button Visual). I have to put the reference to the actual function at two places but that is a small price to pay for the benefit. 

 

 

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class EventClick : MonoBehaviour, IPointerClickHandler
{
public GameObject parent;
public UnityEvent onClick;
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("Clicked: " + parent.name);

if(onClick != null)
onClick.Invoke();
}
}