- Home /
[C#] 3D raycast to sprite. Two cameras.
I have 2 cameras. One is the main camera and the other is a GUI camera. I am trying to raycast from the main camera to get the collider of the sprite but it seems to fail.
I am trying to hit the fire logo there.
help.png
(37.4 kB)
Comment
Please post your Raycast() code attempt so that maybe the problem can be spotted.
i found the answer on the forums already. Thanks anyways robertbu :D
Best Answer
Answer by MewEight · Mar 21, 2014 at 07:36 AM
I found the answer to it on the forums. Posting the answer here to help others who might be interested.
// Put Camera Here
public Camera guiCamera;
void Update()
{
RaycastHit2D hitInfo2D = Physics2D.Raycast(guiCamera.ScreenToWorldPoint(Input.mousePosition),Vector2.zero);
if(hitInfo2D.collider != null)
{
Debug.Log("Object Clicked : " + hitInfo2D.collider.name);
}
}
Credits to JohnGallet ForumLink