- Home /
Change cursor on OnTrigger
After trying to solve this and reading about all sorts of codes I now need some help. The goal is to be able to, when inside OnTrigger, hover the cursor over a door and the cursor will change. It should not change when player is outside triggerarea. My issue is to call the OnMouseEnter function while already inside a void. I'm kinda new and still learning.
public Texture2D cursorTexture;
void OnTriggerStay(Collider other)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
//hover cursor function
{
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (hit.collider.gameObject == gameObject)
{
//code for cursor change when hover
}
}
}
}
}
void OnMouseEnter(){
Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto);
}
void OnMouseExit(){
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
Right now I can be on the other side of the room, hover cursor over door, and it will change.
Your answer
Follow this Question
Related Questions
How to detect mouse leaving / entering the game window? 1 Answer
OnTriggerEnter doesn't work with fast animations/movements 2 Answers
My "Lava " script doesnt work 2 Answers
OnMouseEnter/Exit not working when pressing button to advance scene 2 Answers
Can't seem to get OnMouseExit and Destroy(GameObject) to work properly 1 Answer