예제 #1
0
    void OnMouseDown()                                                                                                    //when the user clicks on this sector
    {
        gameMapScript theGameMapScript = this.gameMap.GetComponent <gameMapScript>();                                     //set a reference to the gameMapScript script of the gameMap
        GameObject    theSelectedUnit  = theGameMapScript.selectedUnit;                                                   //set a reference to the gameMap's selected unit to see if a unit was selected before this sector was clicked on

        theGameMapScript.selectedUnit = null;                                                                             //a sector has now been selected, so set the selectedUnit to null

        if (theSelectedUnit != null && theSelectedUnit.GetComponent <unitScript>().canMoveTo().Contains(this.gameObject)) //if a unit has been selected, and this sector has been clicked, move
        {                                                                                                                 //that unit to this sector, if it is within range
            unitScript theSelectedUnitScript = theSelectedUnit.GetComponent <unitScript>();                               //set a reference to the selected unit's unitScript script
            theSelectedUnitScript.moveUnit(this.gameObject);                                                              //move unit to this sector
        }
    }
예제 #2
0
    void OnMouseDown()                                                                                                //when a building is clicked, it should open the unit buy menu and hide the game map
    {
        gameMapScript theGameMapScript = this.gameMap.GetComponent <gameMapScript>();                                 //set a reference to the gameMapScript script of the gameMap
        GameObject    theSelectedUnit  = theGameMapScript.selectedUnit;                                               //set a reference to the gameMap's selected unit to see if a unit was selected before this sector was clicked on

        theGameMapScript.selectedUnit = null;                                                                         //a sector has now been selected, so set the selectedUnit to null

        if (theSelectedUnit != null && theSelectedUnit.GetComponent <unitScript>().canMoveTo().Contains(this.sector)) //if a unit has been selected, and this building has been clicked, move
        {                                                                                                             //that unit to this sector, if it is within range
            unitScript theSelectedUnitScript = theSelectedUnit.GetComponent <unitScript>();                           //set a reference to the selected unit's unitScript script
            theSelectedUnitScript.moveUnit(this.sector);                                                              //move unit to this sector
        }
        else if (theSelectedUnit == null)
        {
            this.buyUnitCanvas.gameObject.SetActive(true);                                              //open the unit buying canvas
            this.gameMap.gameObject.SetActive(false);                                                   //close the game map
            buyUnitCanvas.GetComponent <unitCanvasScript>().warningMessage.gameObject.SetActive(false); //do not display the warningMessage
            //set the "spawnPoint" value in the buyUnitCanvas' "unitCanvasScript" script so that newly purchased units will spawn on the same sector
            //as the building that they clicked to open the buy unit menu
            this.buyUnitCanvas.GetComponent <unitCanvasScript>().setSpawnPoint(sector.gameObject);
        }
    }