public AttackState(Unit unit, HitPoints target) { this.unit = unit; Debug.Log($"{unit.name} started attacking {target.name}."); this.target = target; targetRadius = target.GetComponent <ObjectRadius>(); }
public void Initialize(HitPoints target, float damage, float speed, Color color) { this.target = target; this.damage = damage; this.speed = speed; renderer.material.SetColor("_Color", color); }
public void ShootProjectile(HitPoints target) { // TODO: Pool projectiles. var projectile = Instantiate(CurrentJob.projectilePrefab, transform.position, Quaternion.identity); projectile.Initialize(target, CurrentJob.damage, CurrentJob.projectileSpeed, UnitTeam.teamColor); }
public override void Update() { var potentialTargets = GameController.Instance.GetEnemyTeam(unit.UnitTeam).GetAllPotentialTargets(); HitPoints closestTarget = null; var distance = AggroRadius; foreach (var potentialTarget in potentialTargets) { var monoBeh = (MonoBehaviour)potentialTarget; var newDistance = Vector3.Distance(unit.transform.position, monoBeh.transform.position); if (newDistance > distance) { continue; } distance = newDistance; closestTarget = potentialTarget; } if (closestTarget == null) { return; } unit.AttackTarget(closestTarget); StopState(); }
public ChaseState(Unit unit, HitPoints target, float stopDistance) { this.target = target; this.stopDistance = stopDistance; agent = unit.Agent; agent.speed = unit.CurrentJob.movementSpeed; path = new NavMeshPath(); targetRadius = target.GetComponent <ObjectRadius>(); }
public void AttackTarget(HitPoints target) { // HACK: Clearing stack to fix strange behaviour causing ClearMovementFromStack(); var attackState = new AttackState(unit, target); attackState.OnStateFinish += (x) => StartSearchingForEnemies(); PushNewStateHandler(attackState); }
public void Initialize(Team team, bool isFinished = false) { HitPoints = GetComponent <HitPoints>(); HitPoints.OnDeath += DeathHandler; Team = team; this.isFinished = isFinished; foreach (var renderer in renderers) { renderer.material.SetColor("_Color", team.teamColor); } HitPoints.Initialize(maxHP); }
public void Initialize(Team team, int unitID, Color color, string playerName) { HitPoints = GetComponent <HitPoints>(); UnitTeam = team; nameplate.text = playerName; IsPlayer = string.IsNullOrEmpty(playerName) == false; UnitID = unitID; name = IsPlayer ? playerName : $"{team.teamName} {unitID}"; renderer.material.SetColor("_Color", color); ChangeJob(defaultJob, true); unitBehaviour.Initialize(this); HitPoints.OnDeath += DeathHandler; }
public void Initialize(Team team, Building buildingPrefab, MapTile tile, TileDirection direction) { HitPoints = GetComponent <HitPoints>(); HitPoints.OnDeath += DeathHandler; Tile = tile; Team = team; Building = Instantiate(buildingPrefab, transform.position, Quaternion.Euler(0, (int)direction * 90, 0), transform); Building.Initialize(team); buildingPoints = 0; progressBar.SetProgress(buildingPoints / Building.buildingPointsCost); resourcesLeftToCollect = new ResourceCollection(Building.cost); State = ConstructionState.GatheringResources; deliveries = new List <Delivery>(); HitPoints.Initialize(maxHP); }
private IEnumerator Attack(HitPoints target) { while (target != null && target.IsAlive && target.IsInRange(transform.position, attackRadius)) { if (timeSinceLastAttack < attackCooldown) { yield return(new WaitForSeconds(attackCooldown - timeSinceLastAttack)); } ShootProjectile(target); timeSinceLastAttack = 0; yield return(new WaitForSeconds(attackCooldown)); } currentAttack = null; }
public void AttackTarget(HitPoints target) => unitBehaviour.AttackTarget(target);
private void ShootProjectile(HitPoints target) { var projectile = Instantiate(projectilePrefab, shootingOrigin.position, Quaternion.identity); projectile.Initialize(target, attackDamage, projectileSpeed, Team.teamColor); }