Ejemplo n.º 1
0
    //builds a tower of type 'inName' and level 'inLevel' at the cell (Xcoordinate,Ycoordinate)
    public GameObject buildTower(string inName, int inLevel, int Xcoordinate, int Ycoordinate)
    {
        //Only the master client can build defenses
        if (!PhotonNetwork.isMasterClient)
        {
            return(null);
        }

        //if this spot is available, build a tower there
        if (availableSpots[Xcoordinate, Ycoordinate])
        {
            //use the photon network instantiate so that other players can see the tower
            GameObject newTower = PhotonNetwork.Instantiate(inName + inLevel, gms.GetWorldPosition(new Vector2(Xcoordinate, Ycoordinate)), Quaternion.identity, 0);
            //rotate tower to face the right direction that humans come from
            newTower.transform.Rotate(0, 90, 0);
            //assign its values in tower script
            TowerScript ts = newTower.GetComponent <TowerScript> ();
            ts.towerLevel    = inLevel;
            ts.towerName     = inName;
            ts.gridPositionX = Xcoordinate;
            ts.gridPositionY = Ycoordinate;
            //to prevent other towers from being built at the same cell
            availableSpots[Xcoordinate, Ycoordinate] = false;
            return(newTower);
        }
        return(null);
    }
Ejemplo n.º 2
0
    //creates a human using Photon Network's Instantiate, so it is visible to all other players
    //takes in the name of the human to be spawned (aka his/her type)
    //and the coordinates of where the human is to be created
    public GameObject spawnHuman(string inName, int Xcoordinate, int Ycoordinate)
    {
        //instantiate a new human on the photon network
        GameObject newHuman = PhotonNetwork.Instantiate(inName, gms.GetWorldPosition(new Vector2(Xcoordinate, Ycoordinate)), Quaternion.identity, 0);

        //to head to the left
        newHuman.transform.Rotate(0, -90, 0);

        return(newHuman);
    }