Hi,
I am trying to write a script where I can see if a certain sprite is clicked on. But it never seems to register when I click on the sprite, because I don’t see the “lets destroy stuff” message in the console. What am I missing?
Some more info: I am using cinemachine, I have the main camera tagged as main camera with perspetive view set. Therefore I use ScreenPointToRay. I have the sprite assigned to the backButton in the editor, with a box collider 2D on it.
void Update () {
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition));
//Use the RaycastHit2D to determine if anything was hit by the click:
if (hit && hit.collider != null && hit.collider == backButton)
{
Debug.Log("Lets destroy stuff");
}
}
}