ameinias
ameinias

Reputation: 1

Unity PhysicsRaycaster not recognizing correct edges of 3D collider with OnMouseEnter

I'm using the PhysicsRaycaster on the MainCamera, trying to detect hover. It seems like it should be very simple but the collider never lines up, it's like it's smaller the to the x+ y- of where it should be.

gif: doesn't hover where i expect

` using UnityEngine;

public class TextOverlay : MonoBehaviour
{
public Texture2D[] cursorTexture;
public Renderer rend;

private void Start()
{

    rend = GetComponent<Renderer>();
    ChangeCursor(false);
}

public void OnMouseEnter()
{
    rend.material.color = Color.red;
    ChangeCursor(true);
}

public void OnMouseOver()
{
    rend.material.color -= new Color(0.1F, 0, 0) * Time.deltaTime;
}


public void OnMouseExit()
{
    rend.material.color = Color.white;
    ChangeCursor(false);
}


public void ChangeCursor(bool value)
{
    Debug.Log("change cursor: " + value);
    if (value)
        Cursor.SetCursor(cursorTexture[1], Vector2.zero, CursorMode.Auto);
    else
        Cursor.SetCursor(cursorTexture[0], Vector2.zero, CursorMode.Auto);

}

}

`

I expect the cursor to change and the sub to highlight red when the cursor passes over the edge of the collider.

I've checked the 3D box collider fits the cube, the Physics Raycaster is attached to the main camera, there are no other cameras, tried three versions of unity, new project, with and without Cinemachine brain. (Will eventually need to work with Cinemachine.) I've tried OnMouseEnter/Exit, OnPointerEnter/Exit, and the EventTrigger.

Upvotes: 0

Views: 18

Answers (0)

Related Questions