// Update is called once per frame void Update() { // Get target in attack range if (_target == null) { _target = GridManager.Instance.GetNearestTargetInRange((int)MapPosition.x, (int)MapPosition.y, _attackRange, GridType.Enemy); if (_target != null) { _attackLine.ShowLine(); _attackLine.EndObject = _target; _attackLine.DrawLine(); } else { _attackLine.HideLine(); } } else // Hide attack line when target out of attack range { Vector2 sub = _target.GetComponent <Grid>().MapPosition - MapPosition; float distance = Mathf.Max(Mathf.Abs(sub.x), Mathf.Abs(sub.y)); if (distance > _attackRange) { _target = null; _attackLine.HideLine(); } } }