Need info

Mattis

Active member
Hi!
Where do I find tutorials setting up more then 1 player? My game is 2 player online, and both characters are different.

How does it work ? Do I need 2 cameras in the scene or ?

I don't understand.
 
There is a demo scene in the addon folder. From your message, I would answer 2 cameras are not needed, You do not need to divide the screen into 2 parts?
 
Okay. Thanks ! No I don't need to do that, the game is co-op online and loca, I have 2 different characters , I just wonder when there's now only one main camera and that is setup to player 1. I just don't know how this is done in reality.

@Justin ?
 
I have a top view and the character shoots at the point where the cursor is aimed, I synchronize and transfer the position of the cursor to other cars to recreate where to aim and where the bullet will fly.
 
I recommend watching the PUN videos as it shows how to setup the scene. The documentation also explains the setup. Different characters with different players is not available in the PUN demo scene but that is gameplay related and you will need to extend the Spawn Manager.

 
Okay. In Wich way must I extend it? How does it work when pun spawns ? And what about the camera question for the player 2 character.? Can you explain how it's made ?
 
Write your own implementation of character spawn, similar to
C#:
public abstract partial class SpawnManagerBase : MonoBehaviourPunCallbacks, IOnEventCallback


I'm using one character model so far, but I have two prefabs, one for Local, the second Replicator which synchronizes the behavior of the local character on other machines.

The basic script example has the following code:
C#:
// Instantiate the player and let the PhotonNetwork know of the new character.
var player = GameObject.Instantiate(GetCharacterPrefab(newPlayer), spawnPosition, spawnRotation);
var photonView = player.GetComponent<PhotonView>();

Here I am using a character factory. You can try something like this:
C#:
// Instantiate the player and let the PhotonNetwork know of the new character.
bool nonLocalPlayer = Equals(newPlayer, PhotonNetwork.LocalPlayer) == false;
var character = _characterFactory.Create(nonLocalPlayer
    ? CharacterType.Replicator
    : CharacterType.Local);

I took some of the methods from SpawnManagerBase and created my own PunCharacterSpawnManager class, because I don't need GetCharacterPrefab, I use a factory instead.
 
Last edited:
For the second character, everything will work for his client. On other machines, you will synchronize animations, gaze positions, weapons in your hands, etc. There is no need to create a second chamber. In my case, I have a virtual camera and a top view, I transmit over the network the position where the player is aiming, and on other machines I synchronize the position of the look and aim.

P.S. I hope I prompted you to find the solution you need.
 
Top