Crosshair texture does not follow the mouse

Hi

I googled it a lot but could not find anything.

I have this simple script.

I want the crosshair to follow the mouse pointer.

The texture is not following the mouse. It follows the mouse horizontlally but vertically it goes up when I move the mouse down and oppossite. They meet in the middle of the screen.

// script start ///////////////////////////////////

var position : Rect; var crosshairTexture : Texture2D;

function OnGUI () {

position = Rect( Input.mousePosition.x - (crosshairTexture.width / 2), Input.mousePosition.y - (crosshairTexture.height / 2), crosshairTexture.width , crosshairTexture.height );

GUI.DrawTexture( position , crosshairTexture );

}

/////////////////////// end of script ///////////////

You shouldn't use Input.mousePosition in OnGUI...use Event.current.mousePosition instead. It's easier and faster; you don't need to mess with Screen.height:

var crosshairTexture : Texture2D;

function OnGUI () {
    var mousePos = Event.current.mousePosition;
    GUI.DrawTexture( Rect( mousePos.x - (crosshairTexture.width/2),
                           mousePos.y - (crosshairTexture.height/2),
                           crosshairTexture.width,
                           crosshairTexture.height), crosshairTexture);
}

the y position of mouse is 0 from bottom and GUI is y 0 from top. To solve it take `Screen.height` and subtract `mousePosition.y` from it:

var position : Rect; var crosshairTexture : Texture2D;

function OnGUI () {

    position = Rect( Input.mousePosition.x - (crosshairTexture.width / 2), (Screen.height - Input.mousePosition.y) - (crosshairTexture.height / 2), crosshairTexture.width , crosshairTexture.height );

    GUI.DrawTexture( position , crosshairTexture );

}

I used your script but the crosshair is still a few pixels offset but only in full screen in webplayer! works ok when webplayer not in full screen.

...works also ok in standalone. Only in webplayer in fullscreen mode the crosshair texture does not follow the mouse. mouse is pointing to the bottom of the texture. I've copied your script exactly.

How would this be modified to follow a joystick rather than a mouse?

Thanks!