Ejemplo n.º 1
0
    public void SpawnUnitWithButton(int intType)
    {
        Unit     newUnit = null;
        UnitType type    = (UnitType)intType;
        Airport  rax     = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b as Airport && (b as Airport).selected)
            {
                rax = b as Airport;
                break;
            }
        }
        if (rax == null)
        {
            return;
        }
        if (type == UnitType.FIGHTER)
        {
            newUnit       = Instantiate(unit1, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.FIGHTER;
        }
        if (type == UnitType.BOMBER)
        {
            newUnit       = Instantiate(unit2, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.BOMBER;
        }
        if (type == UnitType.COPTER)
        {
            newUnit       = Instantiate(unit3, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.COPTER;
        }
        if (type == UnitType.CAPCOPTER)
        {
            newUnit       = Instantiate(unit4, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.AERIALACE)
        {
            newUnit       = Instantiate(unit5, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.BOMB)
        {
            newUnit       = Instantiate(unit6, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }

        if (!rax.Cell.IsTaken && rax.spawnUnit && rax.selected && rax.CanSpawnUnit(newUnit))
        {
            rax.SpawnUnit(newUnit);
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = rax.transform.position.x;
            update.newLocationY = rax.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        rax.spawnUnit = false;
    }