Esempio n. 1
0
        private void BuildWall()
        {
            var PillarsCopy = new WallPiecePreview[Pillars.Count];

            Pillars.CopyTo(PillarsCopy);

            GameObject firstObject = null;

            for (int i = 0; i < PillarsCopy.Length; i++)
            {
                if (PillarsCopy[i].CanBeBuilt)
                {
                    if (firstObject == null)
                    {
                        firstObject = Instantiate(PillarPrefab, PillarsCopy[i].transform.position, PillarsCopy[i].transform.rotation);
                    }
                    else
                    {
                        builtPillar = Instantiate(PillarPrefab, PillarsCopy[i].transform.position, PillarsCopy[i].transform.rotation);
                    }
                }

                if (i == PillarsCopy.Length - 1)
                {
                    continue;
                }

                Destroy(Pillars[i].gameObject);
            }

            var WallsCopy = new WallPiecePreview[Walls.Count];

            Walls.CopyTo(WallsCopy);

            for (int i = 0; i < WallsCopy.Length; i++)
            {
                if (WallsCopy[i].CanBeBuilt)
                {
                    var wall = Instantiate(WallPrefab, WallsCopy[i].transform.position, WallsCopy[i].transform.rotation);
                    wall.GetComponent <MeshRenderer>().material.SetFloat("_PercentageX", wallAlphaX);
                    wall.GetComponent <BoxCollider>().size = wall.GetComponent <NavMeshObstacle>().size *WallOffsetMultiplier;
                }

                Destroy(Walls[i].gameObject);
            }

            Building firstBuilding = firstObject.GetComponent <Building>();

            if (firstBuilding != null)
            {
                firstBuilding.GetBuildingHealthSystem().Built = false;
                firstBuilding.Team = SelectionManager.Instance.m_Team;
                firstBuilding.GetBuildingData().team = SelectionManager.Instance.m_Team;

                foreach (var unit in SelectionManager.SelectedUnits.Where(unit => unit.HasState(typeof(BuildState))))
                {
                    unit.OnTarget(firstBuilding);
                    break;
                }
            }

            WallPiecePreview _FirstPillar = secondPillar;

            Clear();

            firstPillar = _FirstPillar;
            Pillars.Add(firstPillar);
            SetUpBuilding();

            //gameObject.SetActive(false);
        }