I don't know why i can't detect by ray sth. tagged,

I am trying detect plane by ray but don’t know why i can’t

RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, 20)) 
	{
	Debug.Log (1);

	if (hit.collider.gameObject.name == "ciemnosc")
	Debug.Log (2);
				
	if (hit.collider.gameObject.GetComponent<detect>() == true)
	Debug.Log (2);

	}

I never turn on Debug.Log (2), but always turn on Debug.Log(1)

Hi @unity_JVTjdUJooO4gMA
I am a bit late, but I hope it will be helpful anyway.

1st condition should work ok with any object named “ciemnosc” that has a collider.

If you are trying to know if the object has a Detect component attached to it, the condition should be:

if (hit.collider.gameObject.GetComponent<Detect>() != null)
    Debug.Log ("3");
}