示例#1
0
    public void SpawnPlayer(int iD, string username, Vector3 position, bool isFacingRight, bool isDead, bool justJoined)
    {
        GameObject player;
        GameObject prefab;

        bool localClient = iD == Client.Instance.ClientID;

        if (localClient)
        {
            if (IsMobileSupported())
            {
                prefab = MobileLocalPlayerPrefab;
            }
            else
            {
                prefab = LocalPlayerPrefab;
            }
            Debug.Log($"You, player: {iD} have been spawned.");
        }
        else
        {
            prefab = PlayerPrefab;
            Debug.Log($"Player: {iD} has been spawned.");
        }
        player = Instantiate(prefab, position, Quaternion.identity);

        PlayerManager playerManager = player.GetComponent <PlayerManager>();

        playerManager.Initialise(iD, username);
        PlayerDictionary.Add(iD, playerManager);

        NonLocalPlayerHealth healthManager = player.GetComponentInChildren <NonLocalPlayerHealth>();

        healthManager?.SetOwnerClientID(iD);

        NonLocalPlayerMovement playerMovement = player.GetComponentInChildren <NonLocalPlayerMovement>();

        playerMovement?.SetOwnerClientID(iD);

        NonLocalPlayerAnimations playerAnimations = player.GetComponentInChildren <NonLocalPlayerAnimations>();

        playerAnimations?.SetOwnerClientID(iD);

        IGun playerGun = player.GetComponentInChildren <IGun>();

        playerGun?.SetOwnerClientID(iD);

        if (!isFacingRight)
        {
            playerAnimations.FlipSprite();
        }

        StartCoroutine(playerManager.IsPlayerDeadUponSpawning(isDead));

        OnPlayerConnected?.Invoke(iD, username, justJoined);
    }