- Home /
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)
Comment
Ok, so second option (with script "detect") works, but can I do it somehow with tag ?
Answer by udunadmin · Feb 18, 2021 at 07:25 PM
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");
}
Your answer
Follow this Question
Related Questions
Click&Drag Misterious Disappearing! 1 Answer
how to get info on what raycast hitted 1 Answer
Need Help with RayCast. No Vector? 1 Answer
how to select an object with raycasting 1 Answer
hit coin collider 2 Answers