- Home /
How to make a raycaste ui script.
I have a game in progress. I have a world space canvas and some buttons on it. The cursor is in lock state (btw it is a first person game) . I want to know how to click it using raycaste because normal clicks don't work.
Answer by MSavioti · Mar 22, 2021 at 06:44 PM
Here's a practical example to use Graphics Raycaster:
https://docs.unity3d.com/2017.3/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html
You can find the reference to it in a component in your canvas.
Alternatively you can have an in-world rigid body collider in the scene that sits above the button.
Yes I also tried in world colliders and it works fine But it doesn't have the button animations and it is more efficient to use a canvas then many colliders.
Answer by mrVentures · Mar 21, 2021 at 11:40 PM
"....I want to know how to click it" Click what? The cursor itself? Please provide images, code, and what research you have done on google so far.
I want to click the button. The problem is not world space canvas or the button it's self. I tried googling it I sat down for almost 5 hours and The only thing I could find was this video made by code monkey Link:https://youtu.be/pIzWlfbVORU Time stamp : 00:50.
I found out that their is something called a Graphic Raycaster . But I can't seem to find how to use it