- Home /
This question was
closed Jun 03, 2020 at 06:11 PM by
peruzor for the following reason:
Question is solved!
Question by
peruzor · Jun 02, 2020 at 05:31 PM ·
cameraraycastraycasthit2dmain camera
[Solved] Raycast2D and Main Camera
Hello everybody!
I got a problem with Raycast2D and Camera.
Somehow, my logic works without enter on Maximize on Play, but when i do, everything stops to working.
This is my code
void Update()
{
if (Input.GetMouseButton(0))
{
Vector2 rayOrigin = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hitinfo = Physics2D.Raycast(rayOrigin, Vector2.zero);
if (hitinfo.collider != null)
{
Debug.Log(hitinfo.collider.name);
}
}
}
This is my camera in Full Screen Mode 
And this is my camera on normal mode 
Thanks!
[Edit] I tested with my cellphone (via Unity Remote5) and works. Only my maximized is not working.
[Edit2] Guys! I figured out! I forgot to set my canvas UI Scale Mode to Scale with Screen Size and my render mode to Screen Space - Camera
cameramaximized.png
(33.2 kB)
normalcamera.png
(30.5 kB)
Comment
Follow this Question
Related Questions
Drag Camera only when raycasting Terrain 1 Answer
Camera Zoom in&out 2 Answers
Raycast based on crosshair on screen 1 Answer
Raycast and First Person Controller 2 Answers
Raycast detects 2/3 of a collider? 0 Answers