示例#1
0
    public void spawnBasicAntUnit()
    {
        if (hasAuthority)
        {
            WorldHandler localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler>();

            if (WorldHandler.countUnits() < localPlayer.maxUnits)
            {     // if you have less units than the max number of units, it is okay to spawn more units.
                if (localPlayer.resourcesCount > localPlayer.BasicAntCost)
                { // if you have enough unit space and you have enough resources
                    Cmd_SpawnAntUnit(transform.position);

                    localPlayer.resourcesCount -= localPlayer.BasicAntCost; // after spawning unit, spend 15 resources.
                }
                else if (localPlayer.resourcesCount < localPlayer.BasicAntCost)
                {
                    WorldHandler.PlayResourcesSound(); // You require more resources (audio clip);
                }
            }
            else if (WorldHandler.countUnits() > localPlayer.maxUnits)
            {
                WorldHandler.PlayUnitCapSound(); // You require more unit Cap audio clip (this is if we decide to add a way for the player to increase the unit cap);
            }
        }
    }