InvokeRepeating couldn't be called for a function inside an instanced object

Hi, i’m working actualy on a Atb gauge for multiple character and i got some trouble with the InvokeRepeating method who i use to fill up my gauge, there is a template of the whole script (ask me if more line of the script are needed), i’ve tryed multiple way to make it work too.

Way I want the script to work:

In BattleSystem script :

var characterPicture : Texture;
var character : BaseStats;

Start()
{
// create the new character & start invoke repeating
character = new BaseStats("My character", characterPicture, 9, 9, 9, 9, 10000000);
character.AtbConfig(); //configure speed of the atb gauge
character.atbGaugeFull = false;
InvokeRepeating("character.AtbGaugeOn",0,character.atbSpeedTime);
}

In CharacterStats script :

BaseStats class
{

// ...stats for character & function used by it

function AtbGaugeOn()
{
	if(atbGaugeFull == false)
	{
		atbCurrentTime += atbSpeedTime;
		if(atbCurrentTime >= baseAtbFillTime)
		{
			atbGaugeFull = true;
			atbCurrentTime = 0;
		}
	}
}

// ...another stats & constructor
}

Error = Trying to invoke method: BattleSystem.character.AtbGaugeOn couldn’t be called.

Way it work but who i won’t him to work:

In BattleSystem script :

var characterPicture : Texture;
var character : BaseStats;

Start()
{
// create the new character & start invoke repeating
character = new BaseStats("My character", characterPicture, 9, 9, 9, 9, 10000000);
character.AtbConfig(); //configure speed of the atb gauge
character.atbGaugeFull = false;
InvokeRepeating("AtbGaugeOn",0,character.atbSpeedTime);
}

function AtbGaugeOn()
{
	if(character.atbGaugeFull == false)
	{
		character.atbCurrentTime += character.atbSpeedTime;
		if(character.atbCurrentTime >= character.baseAtbFillTime)
		{
			character.atbGaugeFull = true;
			character.atbCurrentTime = 0;
		}
	}
}

Actualy i want 1 atb gauge for ech character & npc in the battle who fill up over time depend on the speed value of the actual character or npc. on this script as i got only one character it can work on both way but soon i will have 6 character i don’t think the second way will work properly.
I’ve tryed to fill the gauge with a while loop but unity crash when used :

function AtbGaugeOn()
{
	while(atbGaugeFull == false)
	{
		atbCurrentTime += (atbSpeedTime*Time.deltaTime);
		if(atbCurrentTime >= baseAtbFillTime)
		{
			atbGaugeFull = true;
			atbCurrentTime = 0;
		}
	}
}

Thx in advance for any help.

Ps: Please apologize my poor english i’m not a native user of it.

You can’t use InvokeRepeating on a method which isn’t on a MonoBehaviour - so you wil have to use a coroutine:

function AtbGaugeOn() : IEnumerator
{
    var lastTime = Time.time;
    while(atbGaugeFull == false)
    {
       atbCurrentTime += (atbSpeedTime*(Time.time - lastTime));
       lastTime = Time.time;
       if(atbCurrentTime >= baseAtbFillTime)
       {
         atbGaugeFull = true;
         atbCurrentTime = 0;
       }
        yield WaitForSeconds(atbSpeedTime/* Put your delay here */);
    }
}

Then do

StartCoroutine(character.AtbGaugeOn());

The way it’s coded may not be right though, it will only do this once until the gauge is full at the moment