You can use a Line Renderer Component attached to some gameobject, then you assign the desired material and you can via code specify the positions of the points:
LineRenderer lineRenderer = GetComponent<LineRenderer>();
Vector3[] positions = {Vector3.zero, someOtherVector3};
lineRenderer.SetPositions(positions);
Note: you can use as many points as you need.
Note 2: No matter that your game is 2D, you can use Vector3, just keep in mind that the z is 0.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…