void Start()
 {
     animator     = GetComponent <Animator>();
     navMesh      = GetComponent <NavMeshAgent>();
     CurrentState = PreviousState = BuilderStates.IDLE;
     targetPos    = Vector3.zero;
 }
 void UpdateLogic()
 {
     if (Health <= 0)
     {
         isDead       = true;
         CurrentState = BuilderStates.DIE;
     }
     if (!isSelected)
     {
         transform.Find("SelectionCirclePrefab").gameObject.SetActive(false);
     }
 }
    void Update()
    {
        navMesh.isStopped = true;
        UpdateLogic();
        switch (CurrentState)
        {
        case BuilderStates.MOVE:
            // var isEnemyClose = IsEnemyClose();
            if (Vector3.Distance(transform.position, targetPos) > relaxDistance)
            {
                isMoving = true;
                GotoDestination(targetPos);
            }
            else
            {
                isMoving     = false;
                CurrentState = BuilderStates.IDLE;
            }
            break;

        case BuilderStates.BUILD:
            // isEnemyClose = IsEnemyClose();
            isBuilding = false;
            if (Vector3.Distance(transform.position, targetPos) > baseDistanceOffset)
            {
                isMoving = true;
                GotoDestination(targetPos);
            }
            else
            {
                isBuilding = true;
                isMoving   = false;
            }

            Debug.Log("Is building " + isBuilding);
            Debug.Log(currentBuildInstance);
            if (isBuilding && currentBuildInstance == null)
            {
                var buildPrefab = (ToBuild == BuildingType.WALL) ? wallPrefab : towerPrefab;
                currentBuildInstance = Instantiate(buildPrefab, buildPosition, buildRotation);
                var tower = currentBuildInstance.GetComponent <Tower>();
                tower.delay = tower.delay / totalCurrentBuilders;
                tower.StartBuilding();
            }
            else if (isBuilding && currentBuildInstance != null)
            {
                var tower = currentBuildInstance.GetComponent <Tower>();
                Debug.Log("Tower " + tower.IsReady);
                if (tower.IsReady)
                {
                    currentBuildInstance = null;
                    isBuilding           = false;
                    CurrentState         = BuilderStates.IDLE;
                }
            }

            Debug.Log(currentBuildInstance);

            break;

        case BuilderStates.IDLE:

            break;

        case BuilderStates.DIE:
            if (deathDelay >= 5F)
            {
                gameObject.SetActive(false);
            }
            deathDelay += Time.deltaTime;
            break;

        default:
            break;
        }

        UpdateAnimation();
    }