Exemple #1
0
    /// <summary>
    /// Spawns a player on the netowrk. Responsible for spawning all things related to
    /// the player (the ball).
    /// </summary>
    /// <param name="code">The message data from the packets</param>
    internal void SpawnPlayerOnNetwork(string code)
    {
        string[] splitcode = code.Split(':');
        int      id        = int.Parse(splitcode[1]);
        int      team      = int.Parse(splitcode[2]);

        GameObject player = network.GetPlayerOfID(id);

        player      = Instantiate(_characterPrefab);
        player.name = id.ToString();
        player.GetComponent <PlayerScoreTracker>().Init(id);

        player.GetComponent <EnemyAnimation>().SetMaterial(network.GetMaterialOfPlayer(team));

        if (team == network.GetMyTeam())
        {
            EventController.FireEvent(new SetTeamUIMessage(player.transform));
        }

        Vector3 location = RespawnManager.instance.GetRespawnLocationAtIndex(id);

        player.GetComponent <EnemyHealth>().Respawn(location);
        player.GetComponent <EnemyHealth>().MyID = id;

        network.AddNumberOfConnectedPlayers();
        network.AddBallAndPlayerToNetwork(player, id);

        AbilityBall.Abilities off = (AbilityBall.Abilities)(NetworkStoredData.instance.GetOffenseAbility(id) + 1);
        AbilityBall.Abilities def = (AbilityBall.Abilities)(NetworkStoredData.instance.GetOffenseAbility(id) + 3);

        EventController.FireEvent(new InitializeAbilityBall(off, id));
        EventController.FireEvent(new InitializeAbilityBall(def, id));
        EventController.FireEvent(new InitializeAbilityBall(AbilityBall.Abilities.storageBall, id));
    }