- Home /
Use OnMouseEnter/OnMouse Exit with center of screen
The thing is, I wanna do something looking like this: Your cursor is locked in the center of the screen and looks like a crosshair. The thing is: I know how to freeze the cursor but I haven't found any way to set it position, and when showcursor is set to false, OnMouseOver and OnMouseExit doesn't work.
Here is my code:
public bool display = false;
public string text = "";
public void OnGUI()
{
GUI.backgroundColor = Color.white;
GUI.color = Color.cyan;
GUI.Label (new Rect(Screen.width/2-20, Screen.height/2-50, 100, 50), text);
}
public void OnMouseOver ()
{
Debug.Log (Vector3.Distance (Camera.main.transform.position, transform.position));
if (Vector3.Distance (Camera.main.transform.position, transform.position) < 3)
{
text = "Interact";
renderer.material.shader = Shader.Find("Outlined/Silhouetted Bumped Diffuse");
}
else
{
text = "";
renderer.material.shader = Shader.Find("Diffuse");
}
}
public void OnMouseExit ()
{
Debug.Log ("Exit");
renderer.material.shader = Shader.Find ("Diffuse");
text = "";
}
Is there anyway to make OnMouseOver and OnMouseExit work with the center of the screen?
Answer by Graham-Dunnett · Jan 14, 2015 at 12:59 PM
If the mouse isn't moving it's not going to move over anything. Instead, perhaps work out if the objects that are moving have passed the centre of the screen. Guess that'll need a ray cast.
Your answer
Follow this Question
Related Questions
OnMouseUp() not working like meant 1 Answer
Multiple Cars not working 1 Answer
custom mouse changing when hovering over objects 1 Answer
Left Click Script Problems 1 Answer
How Do I Lock the Cursor to the Center of the Screen? 1 Answer