MaximilienBlanchardBizien1 a6778d8b72 Fixed an issue where the player couldn't consistently bring up the upgrade option when trying to click on units that were specifically in the castle's shooting range. (#1)
Reviewed-on: #1
Co-authored-by: MaximilienBlanchardBizien1 <maximilien.blanchard-bizien.1@ens.etsmtl.ca>
Co-committed-by: MaximilienBlanchardBizien1 <maximilien.blanchard-bizien.1@ens.etsmtl.ca>
2025-02-13 21:30:36 +00:00

64 lines
1.3 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();
}
}