I’m guessing you were following First Gear Games tutorials with PUN 2 on youtube. Which is actually where I send people who are starting out with Photon. His tutorial is a great starting place! Though I do agree with you that he did over complicate things a bit. But he gives you the base of what you need, and you only grow from there. You start seeing how his code works and how he uses things only to branch off and write your own. Either that or you were watching InfoGamer’s who does a better job explaining but has too much content imo atm. So spread out, which I guess can be a good thing with learning.
For example, I handle my entire player list in 1 file in under 60 lines of code. My entire code for this is below.
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Photon.Pun;
using Photon.Realtime;
public class PlayerListing : MonoBehaviourPunCallbacks
{
[SerializeField]
private GameObject playerListingPrefab;
[SerializeField]
private Transform playerListContent;
#region PUN 2 Callbacks
public override void OnEnable()
{
base.OnEnable();
//first we need to clear the list of any prior player listings
//from previous games
foreach (Transform child in playerListContent)
{
GameObject.Destroy(child.gameObject);
}
//then we trigger our refresh list function
refreshPlayerListing();
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
//create the players name object
var newPlayerListing = Instantiate(playerListingPrefab, playerListContent);
//and set the players name
newPlayerListing.gameObject.transform.GetChild(0).GetComponent<Text>().text = newPlayer.NickName;
}
public override void OnPlayerLeftRoom(Player otherPlayer)
{
foreach (Transform child in playerListContent)
{
GameObject.Destroy(child.gameObject);
}
//then we trigger our refresh list function
refreshPlayerListing();
}
#endregion
private void refreshPlayerListing()
{
//this adds a player listing prefab for every player in the list
foreach (var playersName in PhotonNetwork.PlayerList)
{
//create the players name object
var newPlayerListing = Instantiate(playerListingPrefab, playerListContent);
//and set the players name
newPlayerListing.gameObject.transform.GetChild(0).GetComponent<Text>().text = playersName.NickName;
}
}
}
I was gonna go through and explain the concept of this all, but I feel like it will just create a wall of text. So I’ll make a quick video explaining how to do this and what it does in a few.
As for the sync an object question. The PhotonView is essentially an ID across the network and helps with control (ie. who owns that object). You can send data or update information in said view objects using RPC’s. These are packages sent over the network like say, a player opening a door. We also have PhotonTransformView which is a way of tracking/syncing the objects actual transform or more physical attributes. And of course the more touchy PhotonAnimatorView which I’ve had less success on limiting network lag sync.
It is however good to note that PUN2 now has a new sync method to try out which I still haven’t had a chance to play with despite my excitement for it. You can find it [HERE ]( Photon Unity Networking page-49#post-5638717)on their thread. All good stuff!
EDIT: Here is the video explaining the above code.