Hey forum members,
I have a problem with the hit detection on a rendertexture, let me explain.
I’ve created a rendertexture and added it to a secondary camera(called minimapCamera). This camera is targeted to a plane to simulate a Minimap.
Inside the view of this camera I’ve added some other GameObjects which the user should be able to click.
In my main view I’ve added a GUI-Texture and used the rendertexture as it’s material so I can show my minimap on the screen.
I attached a script to this Gui-Texture which has an OnMouseDown event and added the following code:
Ray ray = minimapCamera.camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log(“hit.transform.name”);
}
I’m also drawing a Line to see where I clicked using the ray.origen and hit.point.
But when I click my minimap it returns the “wrong” transform and the line gets drawn to places it shouldn’t .
Could anyone help me figure out what i’m doing wrong?
As you can see I’m using minimapCamera.camera.ScreenPointToRay so it should be ok.
Thx guys