Hi all, i’m trying to implement cursor in my Third person prototype. So here’s what i’m doing:
void OnGUI () {
GUI.DrawTexture(position, crossHairTexture);
}
void Update(){
RaycastHit hit;
screenCenter = new Vector3(0.5F, 0.5F, 0);
Ray ray = Camera.main.ViewportPointToRay(screenCenter);
Physics.Raycast(ray, out hit, Mathf.Infinity);
Debug.DrawRay(transform.position, ray.direction * 200, Color.yellow);
screenPos = Camera.main.WorldToScreenPoint(hit.point);
position = new Rect(screenPos.x, screenPos.y, crossHairTexture.width, crossHairTexture.height);
}
So i’m shooting a ray from my gun to the center of the screen, and i’m shooting bullets along the ray’s direction. Cursor is locked. I’m trying to position my cursor at hit.point position but it’s not changing it’s position no matter where hit.point is.

why not use a 3d object that is always looking at the screen instead such as a plane? since you are messing with gui, with the draw texture you can’t really see depth but just coordinates from the screen.
unfortunately 3d object reacts the same:

perhaps instead use one of the conversion functions to convert a 3d point to a 2d point on the screen? i forgot the name of it as of this moment
In your code you are not shooting a ray from the gun to the center of the screen, you are shooting a ray from the camera to the center of the screen, which will of course always end up with your cursor at the center of the screen.
It is quite difficult to make something like this handle nicely because the camera is not aligned to your aiming vector, meaning the ray from camera to screen center does not have the same direction as the ray from the gun to screen center. Thats why aiming through the sight of the gun is much easier than aiming from the hip Rambo-style 
What you could try though is cast a ray from camera to screen center like you do now, then make your character aim at the resulting hit.point.
If you did it the other way around, I mean positioning your cursor to wherever the ray from the gun lands, you will have a cursor that jumps all over the screen depending on the level geometry and that is not nice for sure.
You could also take a quick look at how 3rd person aiming was done in the Bootcamp demo.
Cheers,
Pärtel