コード例 #1
0
    public IEnumerator spawnUnit(unitType unitType)                                                            //this function spawns a unit, of type unitType, in sector spawningSector if there is available space
    {
        bool isSpace = false;                                                                                  //this bool is used to keep track of when an empty space in the sector is found

        for (int positionIndex = 0; positionIndex < 3; positionIndex++)                                        //search all possible standing positions on spawning sector too see if the sector is full
        {
            if (spawnSector.GetComponent <sectorScript>().unitsContained[positionIndex] == null && !isSpace)   //if an empty space is found
            {
                gameMainScript GameMainScript = gameMain.GetComponent <gameMainScript>();                      //set reference to gameMain's gameMainScript
                gameMapScript  GameMapScript  = gameMain.transform.GetChild(0).GetComponent <gameMapScript>(); //set reference to gameMap's gameMapScript

                GameMapScript.createUnit(unitType, GameMainScript.currentPlayer, spawnSector);                 //use the "createUnit" funtion in the gameMapScript to spawn a new unit

                isSpace = true;                                                                                //stop searching for spaces
            }
        }

        if (!isSpace)                                   //if no space was found for the unit to stand on the sector show a warning message to the user
        {
            warningMessage.gameObject.SetActive(true);  //show warning message

            yield return(new WaitForSeconds(2));        //show message for 2 seconds

            warningMessage.gameObject.SetActive(false); //stop showing warning message
        }
    }
コード例 #2
0
 // Use this for initialization
 void Start()
 {
     pool = GetComponent("poolScript") as poolScript;
     main = transform.Find("/gameMain").GetComponent("gameMainScript") as gameMainScript;
 }