RayCasted Crosshairs?

I don't like GUI crosshairs, so I drew my own using raycasting, see here:

public class CrossHairs : MonoBehaviour {

    public GameObject crossHairs;
    private void Update() {
        Ray myRay = GameObject.FindWithTag("Camera").camera.ScreenPointToRay(new Vector2(Screen.width/2, Input.mousePosition.y));        

        RaycastHit myHit = new RaycastHit();

      if (Physics.Raycast(myRay, out myHit, Mathf.Infinity)) {
            GameObject inst = (GameObject) Instantiate(crossHairs, myHit.point, transform.rotation);
            Destroy(inst, 0.02f); 
    }
}

The GameObject "crossHairs" is a particle system which is instantiating 1 particle and is using a transparent/cutout/diffuse material (of which is my drawn crosshair).

1 Problem is that it is blinking..and is the top quadrent (I suppose) is covered up by the wall.

I don't really understand what you mean "blinking", but it sounds like you have clipping issues. A couple points:

  1. I don't know how to explain "blinking". You might be better off creating a single billboarded plane that moves around with your camera. There's a billboarding script on the wiki if you want to try that.

  2. As far as clipping goes, you could either create a second camera or write your own shader. The second camera approach would be the same as used to keep the gun drawn over the scenery. Add a second camera that only draws the reticule so that is will always be on top. Or you could use custom z-testing.


    //In a shader. Change your z-testing to always draw this object. ZTest Always