Holding button down to launch object further

I’m trying to make it so that the longer I hold an input button, the farther the “projectile” object is launched from the player’s camera. In this cause, I want to hold the mouse button down for power, and then release it to fire.

This is as far as I got with the code and I am stumped:

public class ShootCrate : MonoBehaviour {

    public GameObject projectile;
    public float fireRate = 0.5F;
    private float nextFire = 0.0F;
    public float power = 0.0F;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetButtonDown("Fire1"))
        {
            Debug.Log("A key or mouse click has been detected");
            power += Time.deltaTime;
        }
        if (Input.GetButtonUp("Fire1"))
        {
            Debug.Log(power);
            nextFire = Time.time + fireRate;
            GameObject crateClone = Instantiate(projectile, transform.position, transform.rotation) as GameObject;
            crateClone.rigidbody.AddForce(transform.forward * 500);
            Destroy(crateClone, 5);
        }
	}
}

Any help is appreciated.

You added up the time used for the power, but then didn’t use that to calculate the force.

I’d recommend multiplying the power times the force, then (optionally) capping it at a certain amount.

public class ShootCrate : MonoBehaviour {

    public GameObject projectile;
    public float fireRate = 0.5F;
    private float nextFire = 0.0F;
    public float power = 0.0F;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        if (Input.GetButtonDown("Fire1"))
        {
            Debug.Log("A key or mouse click has been detected");
            power += Time.deltaTime;
        }
        if (Input.GetButtonUp("Fire1"))
        {
            Debug.Log(power);
            nextFire = Time.time + fireRate;
            GameObject crateClone = Instantiate(projectile, transform.position, transform.rotation) as GameObject;
            crateClone.rigidbody.AddForce(transform.forward * power);
            Destroy(crateClone, 5);
        }
    }
}

Use the power you added to and use it to add force to your rigidbody.