How do I raycast from a UI object? I have tried
Ray ray;
Camera cam;
Transform obj; //UI object
ray = cam.ViewportPointToRay(obj.position);
AND
ray = new Ray(obj.position, obj.forward);
Neither of these seem to work.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityHow do I raycast from a UI object? I have tried
Ray ray;
Camera cam;
Transform obj; //UI object
ray = cam.ViewportPointToRay(obj.position);
AND
ray = new Ray(obj.position, obj.forward);
Neither of these seem to work.
I've figured it out:
ray = cam.ScreenPointToRay(obj.position);