// Update is called once per frame void Update() { var inRange = _positioning.FindAllTaggedByDistanceInRange(_hit.EnemyTag, _hit.Range); if (inRange.Length > 0) { // Stay where we are and AOE all in Hit.Range _navAgent.SetDestination(this.transform.position); _state = State.Attacking; if (!_animator.GetBool("isAttacking")) { _animator.SetTrigger("startAttack"); } } else { _state = State.Roaming; // No one in hit range, roam around if (_navAgent.desiredVelocity.magnitude < 0.1f) { // We have reached the random destination; pick another var randOffset = new Vector3(Random.Range(-RoamingRadius, RoamingRadius), 0.0f, Random.Range(-RoamingRadius, RoamingRadius)); var randDest = this.transform.position + randOffset; _navAgent.SetDestination(randDest); } } }
// Deal Damage to all entities in range public void HitAllInRange() { var inRange = _positioning.FindAllTaggedByDistanceInRange(EnemyTag, Range); foreach (GameObject ent in inRange) { this.HitEntity(ent); } }
// Heal at fixed rate void FixedUpdate() { _healingAccum += this.Healing; _selfHealingAccum += this.SelfHealing; if (_healingAccum > 1.0f) { _healingAccum -= 1.0f; var unitsToHeal = _positioning.FindAllTaggedByDistanceInRange(this.PlayerTag, this.HealingRange); foreach (var unit in unitsToHeal) { unit.GetComponent <Health>().HP += 1; } } if (_selfHealingAccum > 1.0f) { _selfHealingAccum -= 1.0f; _health.HP += 1; } }
// Update is called once per frame void Update() { var nearestTargets = _positioning.FindAllTaggedByDistanceInRange(_hit.EnemyTag, DetectionRange); if (nearestTargets.Length == 0) { // No one in range _state = State.Idle; } else { var nearest = nearestTargets[0]; // Move towards nearest _state = State.Targetting; _navAgent.SetDestination(nearest.transform.position); // Hit nearest if in range if (_positioning.DistanceTo(nearest) <= _hit.Range) { _animator.SetTrigger("startAttack"); } } }