Example #1
0
    void Awake()
    {
        rb               = player2Sync.GetComponent <Rigidbody2D>();
        player           = player2Sync.GetComponent <Player>();
        playerTransform  = player2Sync.transform;
        nonLocalMovement = player2Sync.GetComponent <NonLocalPlayerMovement>();

        health     = player.GetHealth();
        lastHealth = health;
        mana       = player.GetMana();
        lastMana   = mana;

        if (!photonView.IsMine)
        {
            //Player is Remote, deactivate the scripts and object that should only be enabled for the local player
            for (int i = 0; i < localScripts.Length; i++)
            {
                localScripts[i].enabled = false;
            }
            for (int i = 0; i < localObjects.Length; i++)
            {
                localObjects[i].SetActive(false);
            }

            player.isNetworkActive = false;
        }
        else
        {
            player.isNetworkActive = true;
        }

        player.nickName.text = photonView.Owner.NickName;
    }
Example #2
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);
    }
 // Start is called before the first frame update
 void Awake()
 {
     playerRigidbody        = GetComponent <Rigidbody2D>();
     player                 = GetComponent <Player>();
     nonLocalPlayerMovement = GetComponent <NonLocalPlayerMovement>();
 }