MaximilienBlanchardBizien1 e36d43d69a - Fixed an issue where the castle arrow couldn't fire at enemies in an angle, and only straight forward;
- Modified the castle's infos so that it fires only 4 arrows per intervals instead of 5.
2025-01-05 16:33:16 -05:00

63 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Castle : Building
{
public float PopulationGiven => GlobalConfig.Instance.Current.populationGivenPerHouse;
[SerializeField]
private Root _root;
public override void Start()
{
base.Start();
}
public override void Update()
{
base.Update();
if (IsEnemyDetected)
{
AttackEnemy();
}
}
public override void LevelStart()
{
ResourceManager.Instance.MaximumPopulation += PopulationGiven * 2;
base.LevelStart();
}
public override void LevelDestroy()
{
ResourceManager.Instance.MaximumPopulation -= PopulationGiven * 2;
base.LevelDestroy();
}
void AttackEnemy()
{
//Attack Cooldown
if (AttackInterval < AttackSpeedWait)
{
for(int i = 0; i < 4 && IsEnemyDetected; i++)
{
Invoke("ShootInterval", 0.1f * i);
if(Enemy.Hp <= 0) IsEnemyDetected = false;
}
AttackSpeedWait = 0f;
}
AttackSpeedWait += Time.deltaTime;
}
void ShootInterval()
{
_root.ShotProjectile();
}
}