Raycast problem

void UpdateLaser()
mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z - Camera.main.transform.position.z));
Vector3 dir = (mousePos - firePoint.transform.position);
float dist = Mathf.Clamp(Vector3.Distance(firePoint.transform.position, mousePos), 0, maxDist);
mousePos = (firePoint.transform.position + (dir.normalized * dist));
RaycastHit hit;
if(Physics.Raycast(firePoint.transform.position, mousePos, out hit))
mousePos = hit.point;
EnemyTarget target = hit.transform.GetComponent();
if(target != null)

        lineRender.SetPosition(0, firePoint.position);
        lineRender.SetPosition(1, mousePos);

This is my code. My raycast doesnt work on right, but works perfectly on left. I want it to work on all sides. What is the problem you think?

It was because I used 3d raycast for 2d game. For anyone curious in the future…