예제 #1
0
    IEnumerator ConstructFloor()
    {
        GameObject floorObject = Instantiate(floorModel, Vector3.zero, Quaternion.identity, myTransform);

        floorObject.name = string.Concat("Floor", floors.Count);
        Floor floor = floorObject.GetComponent <Floor>();

        floor.floorIndex = floors.Count;
        floor.myTransform.localPosition = Vector3.zero;
        floors.Add(floor);
        floor.myTransform.SetParent(TowerBase);

        for (int i = 0; i < objectNumberPerFloor; i++)
        {
            GameObject part = Instantiate(model, Vector3.zero, Quaternion.identity, myTransform);
            part.name = string.Concat("TowerPart", floors.Count * objectNumberPerFloor + i);
            TowerPart towerPart = part.GetComponent <TowerPart>();
            towerPart.myTransform.localEulerAngles = Vector3.zero;
            towerPart.myTransform.localPosition    = new Vector3(0f, model.transform.lossyScale.y, neededRadius);
            towerPart.myTransform.SetParent(floor.myTransform);
            //color the towerPart
            int randomSelectedColorIndex = MyEventSystem.instance.Get("GetRandomSelectedColorIndex");
            towerPart.SetInitialMaterial(MyEventSystem.instance.Get("selectedTowerPartMaterials")[randomSelectedColorIndex]);

            yield return(new WaitForSeconds(buildDelay));

            myTransform.eulerAngles += Vector3.up * angleStep;
        }

        floor.AddToFloor(floor.myTransform.GetComponentsInChildren <TowerPart>());
    }