InvokeRepeating continuously running twice
Running InvokeRepeating for some reason runs my function twice (I see the timer take values of 2, 4, 6, 8, and from the results i get it seems that my whole function gets called twice before printing out in Update
In start I call
InvokeRepeating("MatchUpdate", 1, 1.0f);
which is:
public void MatchUpdate()
{
test = timer;
HPos = false;
APos = false;
HPS = HMor * 0.1f + HCoa * 0.2f + HDef * 0.2f + HMid * 0.5f;
APS = AMor * 0.1f + ACoa * 0.2f + ADef * 0.2f + AMid * 0.5f;
Possession = HPS / (HPS + APS) + Random.Range(-5, 5);
BPos = Random.Range(-5, 5);
if (BPos <= Possession)
HPos = true;
else
APos = true;
HPass = 0.25f * HCoa + 0.55f * HMid + 0.1f * Random.Range(0, 100) + 0.1f * HMor;
APass = 0.25f * ACoa + 0.55f * AMid + 0.1f * Random.Range(0, 100) + 0.1f * AMor;
HDefend = 0.3f * HCoa + 0.4f * HMid + 0.25f * HDef + 0.05f * Random.Range(0, 100);
ADefend = 0.3f * ACoa + 0.4f * AMid + 0.25f * ADef + 0.05f * Random.Range(0, 100);
HShoot = 0.6f * HAtk + 0.1f * HMor + 0.3f * Random.Range(0, 100);
AShoot = 0.6f * AAtk + 0.1f * AMor + 0.3f * Random.Range(0, 100);
HBlock = 0.7f * HDef + 0.2f * HCoa + 0.1f * HMor;
ABlock = 0.7f * ADef + 0.2f * ACoa + 0.1f * AMor;
if (HPos)
{
StatHPos++;
Pass = HPass - ADefend;
if (Pass <0)
Pass = 0;
if ((Pass + 10) >= Random.Range (0,100))
{
StatHShoot++;
if (HShoot - ABlock >= 0)
{
StatHGoals++;
}
}
}
else
{
StatAPos++;
Pass = APass - HDefend;
if (Pass <0)
Pass = 0;
if ((Pass + 10) >= Random.Range (0,100))
{
StatAShoot++;
if (AShoot - HBlock >= 0)
{
StatAGoals++;
}
}
}
timer++;
}
And I print out stats/results via another script, which get printed after every 2 calls of MatchUpdate. (Also I used the public variable "test" to monitor timer, and in the Inspector it still looks like it's getting called twice every time)
Tried to place a Debug.Log("i'm running"); into ? Check the Console how often it fires.
Are you sure you only call it from one gameobject in the scene?
Your answer
Follow this Question
Related Questions
SNAKE - How to change InvokeRepeating rate? 0 Answers
how can i increese the repete rate in invoke repeting after some time 1 Answer
Invoke () Working like InvokeRepeating () 2 Answers
Invoke repeating wont repeat 1 Answer
Optimization: how to do a checking less often than within an Update 2 Answers