How to initiate global cooldown?

Hi, so i am making a third person “shooter” type game where the player character has multiple abilities. What i want, is to be able to set off a global cooldown whenever any on those abilities is activated. For example i activate the ability nr 1. and every ability suffers a cooldown of 0.5 seconds plus the ability that was activated suffers 1.5 seconds more cooldown(so 2 seconds total for the ability nr 1). I have made seperate scripts for every ability and each one of those scripts has the same function “function Cooldown()” in them. Should i merge the scripts or can i make this happen another way?

`function LateUpdate () {
ShootFireBall();
Cooldown(cooldown);
	if(!gameObject.GetComponent(ShootFrostBolt).onCooldown){
	Debug.Log("Frostbolti cooldown");
	gameObject.GetComponent(ShootFrostBolt).Cooldown(1);
}
}

function Cooldown(cooldown:float) {
timer += Time.deltaTime;
if(timer >= cooldown) timer = cooldown;

if(timer < cooldown) onCooldown = true;
else onCooldown = false;
return onCooldown;

}`

and a similar piece of code on the ShootFrostBolt script.

You could merge all ability scripts in a single code, or use a common script (an already existing player script, or a new one) with the code below:

// define an identifier for each ability (Size must be the last enum
// item: it's just a trick to know how much abilities were defined):
enum Abilities { FireBall, FrostBolt, OtherThing, Size };

var cooldownTimes = new float[Abilities.Size];
var regularTime: float = 0.5;
var extraTime: float = 1.5;

function SetCooldown(ab: Abilities){
  for (i = 0; i < Abilities.Size; i++){
    var t = regularTime; // start with regular time
    if (ab == i) t += extraTime; // add extra time for selected ability
    if (Time.time < cooldownTimes*) // if already in cooldown time...*
 _t += cooldownTimes*; // extend it...*_
 _*else*_
 _*t += Time.time; // else start the new cooldown time*_
 _cooldownTimes *= t;*_
 _*}*_
_*}*_
_*function OnCooldown(ab: Abilities): boolean {*_
 _*return Time.time < cooldownTimes[ab];*_
_*}*_
_*
*_

Supposing the code above is in a script called “Cooldown.js”, you could use something like this in each ability script:


var cooldownScript: Cooldown;
function Start(){
// get a reference to the Cooldown script at Start
cooldownScript = GetComponent(Cooldown);
}
// when activating some ability, do something like this:
if (OnCooldown(Abilities.FireBall) == false){ // if not in cooldown…
ShootFireBall(); // use the ability…
// and set all cooldown timers at once:
cooldownScript.SetCooldown(Abilities.FireBall);
}

Even if you decide to merge the scripts, the first code sample may be used to control the cooldown times - just omit the cooldownScript. part and the GetComponent at Start.