private void SetTargetWithinRange(IZombieDamageable target, bool withinRange) { if (target == this.target) { this.targetWithinRange = withinRange; } }
public void Update() { if (this.IsDestroyed()) { this.target = null; return; } if (this.target == null || this.target.IsDestroyed()) { this.target = this.sight.Closest; } if (this.target == null || this.target.IsDestroyed()) { this.target = GameController.Instance.car; } if (this.moving) { this.transform.rotation = Quaternion.Euler(new Vector3(0, 0, (((Vector2)this.target.Transform().position) - (Vector2)this.transform.position).AngleWithVector2Up())); this.transform.position += (this.target.Transform().position - this.transform.position).normalized * this.speed * Time.deltaTime; } this.timeBeforeNextAttack -= Time.deltaTime; if (this.timeBeforeNextAttack <= 0 && this.target != null && this.targetWithinRange) { this.target.TakeZombieDamages(this.damages); this.timeBeforeNextAttack = 1 / this.attackFrequency; } }
private void SetTarget(IZombieDamageable newTarget) { this.target = newTarget ?? GameController.Instance.car; this.targetWithinRange = this.attackRange.IsWithinRange(this.target); }