So here is the case.
First of all i tried to get rid of NullReference when there are no enemies to track. So i changed the aimWeapon method:
void aimWeapon()
{
if (target == null)
{
Attack(false);
}
else
{
float targetDistance = Vector3.Distance(transform.position,target.position);
weapon.transform.LookAt(target);
if(targetDistance < range)
{
Attack(true);
}
else
{
Attack(false);
}
}
Tested and the null references dropped.
But now, i see an another bug to fix.
In condition when there are a lot of towers and the enemy is not yet instantiated i see that enemies that get instatiated are destroyed with one projectile.
Here is a link to a video to illustrate the problem. On the 8th second the towers start to oneshot instantiated enemies.
I checked the HP of enemies everything looks good. Maybe the problem is that the enemy lacks time to get the hp parameter after instantiating?
I don’t know if this issue will be discussed in the next lecture, so decided to ask the question here.
Thx beforehand