Example #1
0
        void DeplaceTower(MoveableTower tower, SingleTowerPlacementArea area)
        {
            if (area == null)
            {
                return;
            }

            else
            {
                Vector3 targetPosition = area.transform.position;
                float   dist           = Vector3.Distance(tower.transform.position, targetPosition);

                if (dist < 0.1f)
                {
                    tower.transform.position = targetPosition;
                    IntVector2 gridPosition = area.WorldToGrid(targetPosition, dimensions);
                    area.Occupy(gridPosition, dimensions);
                    tower.currentBase = area;
                    return;
                }

                else
                {
                    tower.transform.LookAt(targetPosition, Vector3.up);
                    tower.transform.position += tower.transform.forward * speed * Time.deltaTime;
                }
            }
        }
Example #2
0
        private void Preparation()
        {
            towers       = GetCurrentTowers();
            nearestAgent = GetNearestAgent();

            possibleBases.Clear();

            foreach (SingleTowerPlacementArea area in allBases)
            {
                area.isSelected = false;
            }
            foreach (MoveableTower tower in towers)
            {
                AttackAffector attackAffector = tower.gameObject.transform.GetChild(1).GetChild(0).GetComponent <AttackAffector>();
                attackAffector.enabled = true;
                SingleTowerPlacementArea selectedBase = SearchNearestBase(nearestAgent);
                IntVector2 gridPosition = selectedBase.WorldToGrid(selectedBase.transform.position, dimensions);
                selectedBase.Clear(gridPosition, dimensions);
                possibleBases.Add(selectedBase);
                tower.currentBase.Clear(gridPosition, dimensions);
                tower.currentBase = null;
            }
        }