Drawline for a longer distance


I have this code that draws a line to the mouse cursor. What i want to achive is drawing it “beyond” the cursor. To be more specific id like to draw a line to the mouse and then further with the same direction.

The line is suppose to symbolize a bullets trajectory which should not ofcourse stop at the mouse position but continue further.

if (Input.GetButtonDown("Fire1")) {
            mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, -.5f);
            lookPos = new Vector3(Camera.main.ScreenToWorldPoint (mousePos).x,Camera.main.ScreenToWorldPoint (mousePos).y,this.transform.position.z);
            lookPos = lookPos - transform.position;

            float angle = Mathf.Atan2 (lookPos.y, lookPos.x) * Mathf.Rad2Deg + 90;
            transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
            RaycastHit2D hit = Physics2D.Raycast (muzzle.transform.position, (mousePos - muzzle.position), weaponRange, whatToHit);

            if (Time.time > nextFire) 
                nextFire = Time.time + fireRate;
                Debug.DrawLine (muzzle.position, (lookPos+muzzle.position), Color.red,0.05f);
                Debug.Log ("shot");

I have tried to fiddle with

Debug.DrawLine (muzzle.position, (lookPos+muzzle.position), Color.red,0.05f);

but to no success.

Any help is appretiated!

Your line is only getting drawn for the frame that is resetting the nextFire variable.

So if you are getting more than 100 fps, this line is only displaying for one tenth of a second.

Also, depending on which game object this behavior is attached to, you may not see the line because it is drawing in the look direction of the camera.