Reputation: 49
I get the button using this:
Button button = GameObject.FindGameObjectWithTag("MainCanvas").GetComponentInChildren<Button>();
And then I do:
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, hit))
{
if (button.collider.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit))
{
//Code to run when button clicked
}
}
}
However I keep getting errors on this. Any idea where I've gone wrong?
Error:
Argument 1: Cannot convert from UnityEngine.Ray to UnityEngine.Vector3 Argument 1: Cannot convert from UnityEngine.RaycastHit to UnityEngine.Vector3 Component.collider is obsolete. Property: collider has been depricated Component does not contain a definition for Raycast and no extension method 'Raycast' accepting a first argument type of 'Component' could be found
Upvotes: 0
Views: 747
Reputation: 8163
Its because there is no such a field as Button.collider
. The compiler has no idea what field you are trying to access. It also is saying that that field has been deprecated so there you go
Upvotes: 1