Charged throw not charging

So I’m trying to get my player to throw an object at a pace which depends on how long they hold down a button for. So, holding it for 2 seconds will make it go further than if they just tapped the button (in this case, the mouse button). Although, it doesn’t seem to increase, any noticeable errors here?
Here’s the script for the player.

  public static float chargeSpeed = 1;
    public float chargeRate = 2;
    public Transform FirePoint;
    public GameObject BallPrefab;
    


    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            chargeSpeed += (Time.deltaTime*chargeRate);
        }

        else if (Input.GetMouseButtonUp(0))
        {

            Instantiate(BallPrefab, FirePoint.position, FirePoint.rotation);

            chargeSpeed = 1;
        }
    }

And then here’s the script for the object being thrown `
public float speed = Throw.chargeSpeed;

public Rigidbody2D rb;

void Start()
{
    Vector2 cursorInWorldPos = (Camera.main.ScreenToWorldPoint(Input.mousePosition))/2 ;

    rb.velocity = cursorInWorldPos * speed;
}`

You should set the speed in your code, immediately after you instantiate the object. Don’t rely on ‘Throw.chargeSpeed’ being a suitable value. It’s bad form to try and ‘pass’ values from one class to another the way you’re trying.

 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         chargeSpeed += (Time.deltaTime*chargeRate);
     }
     else if (Input.GetMouseButtonUp(0))
     {
         Vector2 cursorInWorldPos = (Camera.main.ScreenToWorldPoint(Input.mousePosition))/2;
         GameObject G = Instantiate(BallPrefab, FirePoint.position, FirePoint.rotation);
         G.GetComponent<RigidBody>().velocity = cursorInWorldPos * speed;
         chargeSpeed = 1;
     }
 }

Assuming you’re making something 2D/2.5D, the ‘direction’ vector your using is a little unusual. Normally you’d pick the difference between your ‘shooter’ position and your mouse as the vector. You’d also ‘normalize’ it and then multiply it by speed.

For example, you could try…

Vector2 MyVector = (Input.mousePosition - Camera.main.WorldToScreenPos(Shooter.transform.position)).normalized;

This would give you (1,0) when the mouse is directly above the shooter, (0,1) when it’s to the right of them etc.

If you’re shooting out from the camera in a first-person game, it’d be using ScreenPointToRay on the mouse position to find an appropriate vector that leads ‘out’ of the camera.