- Home /
onMouseOver not working for 3D box?
I've seen a couple posts about this, but none worked, and I would like to avoid re-implementing core functionality, if I can.
The situation is simple: Have a box with box collider. onMouseOver works only in a part of it, depending on where the player is standing.
Attached screenshots highlight the issue (right side: game view, left side: scene view, with camera mouse direction denoted by the red line.)
Why is this happening?
EDIT: The relevant code is:
private void OnMouseOver()
{
mouseOvered = true;
print(playerInTrigger);
if (playerInTrigger)
{
print("in");
playerUIHandler.SetInteractableText(gameObject.name);
}
}
Answer by tanmayband · Jul 23, 2019 at 03:10 PM
I figured it out, turns out, my FirstPersonController's capsule collision was throwing it off. The part where it doesn't detect the box, that's the capsule collision blocking the camera's raycast. Setting my player layer to Ignore Raycast fixed it!
Answer by Tabu · Jul 23, 2019 at 06:53 AM
Can you maybe attach some of the code that you use to get this? It is really hard to understand what you are trying to do. My first thought was that you should be using ScreenPointToWorldPoint or something similar to do this right? If you are already doing this, make sure that you are using the right camera. https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
Oh bananas, that's a good point! Don't know why I didn't come across this when I looked into mouseover. $$anonymous$$aybe it was implied. I'll have to test this out and get back to you, I thought mouseover worked out of the box.
Alright, I've added my code. I don't see how I can fit ScreenToWorld in there.
Your answer
Follow this Question
Related Questions
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Box collider fell "inside" into another one (Collision) 3 Answers
How to use Box Collider limited Camera in a Area?? 0 Answers
boxcollider fixed bounds 1 Answer
Why does transform.Rotate not move the sprite and BoxCollider2D together? 1 Answer