コード例 #1
0
    void SpawnPlayerAt(GameObject spawnPoint, PlayerType playerType, InputDevice input, int playerNumber, Color playerColor)
    {
        GameObject chefPrefab = null;

        switch (playerType)
        {
        case PlayerType.FAT:
            chefPrefab = fatChefPrefab;
            break;

        case PlayerType.THIN:
            chefPrefab = thinChefPrefab;
            break;

        case PlayerType.CRAZY:
            chefPrefab = crazyChefPrefab;
            break;
        }

        if (chefPrefab == null)
        {
            return;                     // Don't spawn the HORDE type
        }
        // Spawn the new player
        GameObject newPlayer = Instantiate(chefPrefab);

        newPlayer.name = playerType.ToString() + " player";

        // Place it at the spawn point
        newPlayer.transform.position = spawnPoint.transform.position;

        PlayerScript newPlayerScript = newPlayer.GetComponent <PlayerScript>();

        // Assign the controller
        newPlayerScript.controller = input;

        newPlayerScript.health       = gameData.playerHealth;
        newPlayerScript.maxHealth    = gameData.playerHealth;
        newPlayerScript.playerNumber = playerNumber;
        newPlayerScript.playerColor  = playerColor;

        statsScript.RegisterStats(newPlayerScript);
        if (healthbars != null)
        {
            healthbars.CreateHealthbar(newPlayer.GetComponent <PlayerScript>());
        }
    }