2.5D laser question C#

Hey, I’m trying to create a laser that goes from the player to the mouseposition.

After reading tons of threads and watching some video tutorials on 3D lasers I’ve come to this:

line.enabled = true;
        Vector3 mousepos = Input.mousePosition;
        //mousepos.z = 0.0f;
        Vector3 mouseposWorld = Camera.main.ScreenToWorldPoint(mousepos);
        Vector3 direction = mousepos - transform.position;


        while (Input.GetButtonDown("Fire1"))
        {
            Ray2D ray = new Ray2D(transform.position, direction) ;
            line.SetPosition(0, ray.origin);
            line.SetPosition(1, ray.GetPoint(10));

            yield return null;
        }
        line.enabled = false;
    }

Result is that I can shoot a laser, but it always shoots in the direction of the middle of my screen.

ok i found it, seems like i was already close, but didnt completetly get how the screentoworldpoint worked