- Home /
GUIDrawTexture Based Crosshairs
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.
So I thought that maybe if I set a boolean as false in start, then to true when the raycast hit something...Then in ONGUI test for if (true). Then use GUI.DrawTexture to draw at a rect?
private void OnGUI() { 
    if (varWeSetWhenRayCastWasTrue) {
        GUI.DrawTexture(new Rect(myHit.point.x, myHit.point.y, 10, 10), myTexture);
    } 
}
I may be confused. What is the best way to a acheive a 'distance' feel to drawn crosshairs?
Sorry, I don't understand the question. Could you clarify what exactly you want to do/know?
I want more of a distance feel to crosshairs. $$anonymous$$ost people think a GUI planted in the center of the screen is the way to go. I disagree. I beleive raycasting is the way, but it comes out blinking for me.
Basically, how do I draw a lazer with raycasting? I guess using a GameObject that instanties 1 particle then immediately destroys it is not how "lazers" are done, i.e. I am not getting the desired effect. How do I create a lazer using raycasting?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                