Esempio n. 1
0
    public override GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId)
    {
        Debug.Log("lobbycreateplay numPlayers: " + numPlayers);
        //sets lobbyPlayer name to playername and matchname to matchname
        //variable changes here only changes the currently spawning object variables these spawning object won't have older objects names etc.
        //must call the functions in onstartclient on the prefab to run(which runs on all objects in server
        //play name will be whatever it was changed to on server
        //so we have to the netManager playerName value from local player OnStartLocalPlayer
        lobbyPlayer = (GameObject)Instantiate(lobbyPlayerPrefab.gameObject);
        lobbyPlayer.GetComponent <lobbyPlayer>().playerName = this.playerName;
        lobbyPlayer.GetComponent <lobbyPlayer>().matchName  = this.matchName;
        //numPlayers controls color on server
        if (numPlayers == 0)
        {
            thisColor   = lobbyPlayer.GetComponent <lobbyPlayer>().myColor = Color.red;
            teamName    = "Red";
            enemyName   = "Blue";
            mySpawnSpot = RedCC.transform.position;
            spawnSpot   = RedSpawn.transform.position;
        }
        else if (numPlayers == 1)
        {
            thisColor   = lobbyPlayer.GetComponent <lobbyPlayer>().myColor = Color.blue;
            teamName    = "Blue";
            enemyName   = "Red";
            mySpawnSpot = BlueCC.transform.position;
            spawnSpot   = BlueSpawn.transform.position;
        }
        else
        {
            thisColor = lobbyPlayer.GetComponent <lobbyPlayer>().myColor = Color.green;
        }

        //-----------Add GameObjects to List for the given connection--------------
        //mySpawnSpot.y -= 55f;
        structForServer.playerInfo pI = new structForServer.playerInfo(playerName, teamName, enemyName, tag, thisColor, mySpawnSpot, spawnSpot);
        playerObjs.Add(conn.connectionId, pI);
        Debug.Log("servercreatelobbyplayer" + connections);
        //foreach (var i in lobbySlots)
        //{
        //    i.GetComponent<lobbyPlayer>().updateAll();
        //}
        return(lobbyPlayer);
    }
Esempio n. 2
0
    public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
    {
        structForServer.playerInfo thisPlayerInfo = playerObjs[conn.connectionId];
        GameObject myCommand = GameObject.Instantiate(gamePlayerPrefab, thisPlayerInfo.mySpawnSpot, Quaternion.identity);

        myCommand.GetComponent <networkPlayer>().playerName = thisPlayerInfo.playerName;
        myCommand.GetComponent <networkPlayer>().teamColor  = thisPlayerInfo.teamName;
        //this.name = teamColor + " Team";
        myCommand.GetComponent <networkPlayer>().enemyColor    = thisPlayerInfo.enemyName;
        myCommand.GetComponent <networkPlayer>().thisCol       = thisPlayerInfo.thisColor;
        myCommand.GetComponent <networkPlayer>().spawnPosition = thisPlayerInfo.mySpawnSpot;
        myCommand.GetComponent <networkPlayer>().unitPosition  = thisPlayerInfo.spawnSpot;
        //myCommand.GetComponent<networkPlayer>().nm = this;
        myCommand.GetComponent <Renderer>().material.color = thisPlayerInfo.thisColor;
        myCommand.name = thisPlayerInfo.teamName + "CC";
        myCommand.GetComponent <CommandClick>().team      = thisPlayerInfo.teamName;
        myCommand.GetComponent <CommandClick>().enemy     = thisPlayerInfo.enemyName;
        myCommand.GetComponent <CommandClick>().myCol     = thisPlayerInfo.thisColor;
        myCommand.GetComponent <CommandClick>().gold      = 4000;
        myCommand.GetComponent <CommandClick>().food      = 100;
        myCommand.GetComponent <CommandClick>().health    = 1000f;
        myCommand.GetComponent <CommandClick>().setHealth = 1000f;


        //myCommand.GetComponent<CommandClick>().nm = this;
        myCommand.layer = LayerMask.NameToLayer(thisPlayerInfo.teamName);
        if (thisPlayerInfo.teamName == "Red")
        {
            myCommand.tag = ("Red Command");
        }
        else
        {
            myCommand.tag = ("Blue Command");
        }
        //myCommand.GetComponent<NetworkIdentity>().AssignClientAuthority(conn);
        myCommand.GetComponent <CommandClick>().myTag = myCommand.tag;


        Debug.Log(teamName);
        return(myCommand);
    }