I am making Third person multiplayer game with unity and Photon i can't get the Instantiating of players right both players are sometimes instantiating the same avatar or sometimes there camera Mix up. I have used Cinemachine Virtual camera and Cinemachine brain on main camera
My Hierarchy
Player Prefeb:
Cinemachine Virtual Cam:
Cinemachine brain cam:
This is my script that is responsible for intantiating players
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Photon.Pun;
using UnityEngine;
public class PlayerInstantiator : MonoBehaviour
{
PhotonView PV;
bool spawnPoint1 = true;
bool spawnPoint2 = true;
public GameObject player1;
public GameObject player2;
public Transform sp1;
public Transform sp2;
private void Update()
{
Debug.Log(CheckPlayers());
if (CheckPlayers() == 1 && spawnPoint1 == true)
{
spawnPoint1 = false;
SpawnMasterPlayer();
}
else if (CheckPlayers() == 2 && spawnPoint2 == true)
{
// SpawnMasterPlayer();
SpawnPlayer2();
spawnPoint2 = false;
}
}
private void SpawnMasterPlayer()
{
if (PV.IsMine)
{
CreateController(player1.name, sp1);
}
}
private void SpawnPlayer2()
{
if (!PV.IsMine)
{
CreateController(player2.name, sp2);
}
}
private int CheckPlayers()
{
return PhotonNetwork.CurrentRoom.PlayerCount;
}
private void Awake()
{
PV = GetComponent<PhotonView>();
}
void CreateController(string name, Transform sp)
{
PhotonNetwork.Instantiate(name, sp.position, Quaternion.identity);
}
}
It takes two spawn points and players Prefeb all have photon View attached but still i cant figure it out
It should intantiate two differnt Avatars and make their camers function properly