Crosshair Y-axis inverted

Hi,

I have a crosshair which is directly in front of the player and moves in the same direction as he is moved. However, when the player is moved up, the crosshair moves down to the same degree, and vice versa. The movement along the X-axis is fine. PlayerTarget is an empty GameObject child of the player that sites ahead of him and at the same X and Y position. The script is attached to the MainCamera.
Any ideas? Cheers

public class GUICrosshair : MonoBehaviour
{
    // The Texture2D object to reference the Crosshair texture in the scene.
    public Texture2D crosshair;

    // A Vector2 object to hold the current position (X and Y coordinates) of the current poistion of the mouse on the screen.
    Vector2 mousePos; // = new Vector2(0, 0);

    GameObject obj;

    Vector3 WtoScr;

    //    private Transform target;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        obj = GameObject.FindGameObjectWithTag("PlayerTarget");

        Debug.Log("transform.position = " + obj.transform.position);


        WtoScr = Camera.main.WorldToScreenPoint(obj.transform.position);

        //      WtoScr = Camera.main.ScreenToWorldPoint(obj.transform.position);

        //      WtoScr = Camera.main.ScreenToViewportPoint(obj.transform.position);

        //      WtoScr = Camera.main.ViewportToScreenPoint(obj.transform.position);

        //      WtoScr = Camera.main.WorldToViewportPoint(obj.transform.position);


        Debug.Log("WorldToScreenPoint = " + WtoScr);

        Vector2 targetPos = new Vector2(obj.transform.position.x, obj.transform.position.y);

        Debug.Log("transform.position = " + obj.transform.position);

        Debug.Log("ray.direction = " + obj.transform.position);

    } // ends Update()


    void OnGUI()
    {
        GUI.DrawTexture(new Rect((WtoScr.x - crosshair.width / 2), (WtoScr.y - crosshair.height / 2), crosshair.width, crosshair.height), crosshair);

    }

}

Your issue is a common one - the GUI system and the camera use different coordinate systems. In the camera, Y is up, and in the GUI Y is down, so 0,0 in the camera is the bottom-left and 0,0 in the GUI in the top-left.

Check out the answer to this post, it’s what you need to solve your problem.