Bug with my attackers

So in the levelcontroller script when we call the

public void AttackerSpawned()
{
numberOfAttackers ++;
}

i just find out that for me it starts with 5 instead of 0 and when the attackers starts to spawn they go up for
10.So i never reach 0 .

My only solution to this was that i write in the Start
numberOfAttackers = numberOfAttackers - 5;

Ugly bugfix :D.

Hi Shaktillar,

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Maybe something is calling the AttackerSpawned method which is not supposed to call that method.


If i make a search

Good job. According to the window at the bottom, AttackerSpawned gets called in the Attacker class only. This means that the problem is somewhere “near” the Attacker object/component.

Maybe there are superfluous Attacker components in your scene. Have you already checked all your game objects in the Hierarchy.

Yes i checked 1 by 1 .No Attacker .

Haha gotcha i got it.Here is the solution:

private void Awake()
{
FindObjectOfType().AttackerSpawned();
}

If i run the program in awake its bugged somehow it gives 5 extra Attacker.Now if i change

private void Start()
{
FindObjectOfType().AttackerSpawned();
}

and put this in Start instead of Awake everything is perfect.The extra 5 Attacker is gone.

1 Like

Good job on fixing the problem! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms