The code below isn’t working. It’s printing “preraycast” and “predef” but not “pretagcheck” or “tag”. What am I doing wrong? P.S. I did check the name and tag of the gameObject. By the way, how do I properly insert code? Thanks! (This is a 2D game)
//code
private void Update() {
if (Input.GetMouseButtonDown(0))
{
Debug.Log("preraycast");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
Debug.Log("predef");
if (Physics.Raycast(ray, out hitInfo))
{
Debug.Log("pretagcheck");
if (hitInfo.collider.gameObject.tag == "Wheat")
{
Debug.Log("tag");
}
}
}
}