- Home /
Box collider and Physics.Raycast
I cast Raycast form camera script and I have only one existing Box collider in scene
if (Physics.Raycast(mousePositionInWorld, transform.forward, 10))
{
Debug.Log("Ray hit something");
}
get message Ray hit something*
But i never get trigger on the box collider gameObject
void OnTriggerEnter(Collider other) {
Debug.Log("Menu hit");
}
Target object is gameObject only with Box collider, and script for trigger checking
So, how is the raycasting supposed to trigger the OnTriggerEnter function?
Answer by Berenger · Mar 19, 2012 at 04:45 PM
As OrangeLightning says, raycast doesn't trigger OnTriggerXXX or OnCollisionXXX functions. Those are called by physic rigidbodies / charactercontrollers.
On the other hand, you can use OnMouseXXX.
Your answer
Follow this Question
Related Questions
Raycast and box collider not working properly 2 Answers
Raycasting vs. Input.GetMouseButtonDown 2 Answers
2D Raycast over multiple objects not working? 1 Answer
Check if RaycastHit variable is different. 3 Answers
Change Raycasr origin 0 Answers