示例#1
0
    void TargetEndGame(NetworkConnection conn, bool success, bool didWin, int playerIfWon)
    {
        if (!gameOver)
        {
            gameOver = true;

            if (success)
            {
                //find winning player
                Sprite winSprite = null;
                string winName   = "Unknown";
                foreach (GameObject p in GameObject.FindGameObjectsWithTag("Player"))
                {
                    PlayerIdentityController pid  = p.GetComponent <PlayerIdentityController>();
                    LocalPlayerIdentity      lpid = p.GetComponent <LocalPlayerIdentity>();

                    int UID = pid ? pid.UID : lpid.UID;

                    if (UID == playerIfWon)
                    {
                        winName   = pid ? pid.name : lpid.name;
                        winSprite = p.GetComponent <SpriteRenderer>().sprite;
                        break;
                    }
                }

                print("Boss died, player wins: " + playerIfWon);

                //we know name and sprite, set it
                endGameWinnerText.text    = string.Format("Winner!\n{0}", winName);
                endGameWinnerImage.sprite = winSprite;

                //display appropriate salute depending on if we won or not
                if (didWin)
                {
                    endGameSalute.text = "Congratulations, noble dwarf.\n\nYou have bested the dungeon and your traitorous kin.\nReturn now, live in luxury, and enjoy your honor!";
                }
                else
                {
                    endGameSalute.text = "Feeble dwarf, you have been dishonored.\n\nYou will return a broken dwarf, or stay to haunt these halls forever.\nSuch is the fate of a weak dwarf.";
                }

                endGameHud.gameObject.SetActive(true);
                menuButton.Select();
            }
            else
            {
                //boss did not die, everyone else did, simply keep the base text and present the menu
                endGameHud.gameObject.SetActive(true);
            }
        }
    }
示例#2
0
    /// <summary>
    /// Links a gameobject with a particular ID
    /// </summary>
    /// <param name="player">The game object to link</param>
    /// <param name="ID">That player's connection ID</param>
    public void LinkObjectToID(GameObject player, int ID)
    {
        playerMap.Add(ID, player);
        PlayerIdentityController identity      = player.GetComponent <PlayerIdentityController>();
        LocalPlayerIdentity      localIdentity = player.GetComponent <LocalPlayerIdentity>();

        if (identity)
        {
            identity.playerAnimIndex = playerMap.Keys.Count - 1;
            string name = playerNames.Count > 0 ? playerNames[Random.Range(0, playerNames.Count)] : "Player " + playerMap.Keys.Count;
            identity.name = name;
            identity.UID  = ID;
        }
        else
        {
            localIdentity.playerAnimIndex = playerMap.Keys.Count - 1;
            localIdentity.name            = "Player 2";
            localIdentity.UID             = ID;
        }

        MultiplayerRunManager.Instance.numPlayers = playerMap.Keys.Count;
    }