Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party Photon 2 "if == local player"

Discussion in 'Multiplayer' started by emreyeni999, Apr 12, 2020.

  1. emreyeni999

    emreyeni999

    Joined:
    Jan 24, 2017
    Posts:
    7
    Hi, I work on an object equipping system for my multiplayer game. I did the wearing part and other stuff but when it come to multiplayer I screwed up. I change the current worn objects from the player prefab with a script and that causes everybody look same in your view. All other players looks they've worn the same objects you choose. I know I have to do some networking stuff inside the script but I don't know what to do. As you can see in the images I sent, the blue player had to wear the red's objects


    (this is the script that creates the objects, HatsScriptable and CapesScriptable includes the item prefabs)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class WearObjectsMultiplayer : MonoBehaviour {
    6.  
    7.  
    8.     public HatsScriptable Hat;
    9.     public CapesScriptable Cape;
    10.  
    11.     public GameObject HeadBone;
    12.     public GameObject NeckBone;
    13.  
    14.  
    15.     void Start()
    16.     {
    17.         EquipHat();
    18.         EquipCape();
    19.     }
    20.  
    21.     public void EquipHat()
    22.     {
    23.         GameObject go = Instantiate(Hat.Prefab, HeadBone.transform.position, HeadBone.transform.rotation);
    24.         go.transform.parent = HeadBone.gameObject.transform;
    25.     }
    26.  
    27.     public void EquipCape()
    28.     {
    29.         GameObject go = Instantiate(Cape.Prefab, NeckBone.transform.position, NeckBone.transform.rotation);
    30.         go.transform.parent = NeckBone.gameObject.transform;
    31.     }
    32.  
    33.  
    34. }
    35.  
    1.png 2.jpg
     
  2. SupinePandora43

    SupinePandora43

    Joined:
    May 13, 2019
    Posts:
    18
    Player 1: *pressed wear button*, *sends wear info to server*
    Server: *Players1.Equip(Wear1)*, *sends "Player 1 weared Wear1" to all players*
    Player 1: *receives info from server* I weared Wear1 !!!
    Player 2: *receives info from server* Player 1 weared Wear1
    Player 3: *receives info from server* Player 1 weared Wear1
     
  3. Marthsen1

    Marthsen1

    Joined:
    Jun 19, 2019
    Posts:
    1
    I don't know if it's any help but photonnetwork has a playerlist and each player has an extension called isLocal. So just loop through your list like so:
    for (int i = 0; i < PhotonNetwork.PlayerList.Length; i++)
    {
    if(PhotonNetwork.PlayerList.IsLocal)
    {
    //Do something
    }
    else
    {
    //Do something else or return
    }
    }
     
    AdmiralFick and DJ_Design like this.