Question by
skymen750 · Apr 06, 2018 at 03:18 PM ·
cameramultiplayerbugpun
Instantiation bug using Photon Unity Network (PUN)
Hello, I'm having an annoying bug in my PUN multiplayer game.
Basically, I'm creating the players using RPC, and assigning the client's player to the MainCamera. This works perfectly in offline mode, but online, it tells me that the MainCamera's player variable has not been assigned.
Here is the script that does this: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NetworkManager : Photon.MonoBehaviour
{
public SpawnManager SpawnManager;
public Camera MainCamera;
public GameObject Player;
// Use this for initialization
void Start () {
if (Global.Instance.Offline)
{
MainCamera.GetComponent<CameraFollow>().player = Instantiate(Player, SpawnManager.PlayersSpawn.SpawnList[0].position, Quaternion.identity);
for (int i = 1; i < SpawnManager.PlayersSpawn.SpawnList.Count; i++)
{
Instantiate(Player, SpawnManager.PlayersSpawn.SpawnList[i].position, Quaternion.identity).GetComponent<PlayerController>().isBot = true;
}
}
else if(PhotonNetwork.isMasterClient)
{
var PlayerList = PhotonNetwork.playerList.Length;
photonView.RPC("CreateLocal", PhotonTargets.All, 0, 0);
}
}
[PunRPC]
public void CreateLocal(int SpawnPnt, int id)
{
MainCamera.GetComponent<CameraFollow>().player = PhotonNetwork.Instantiate(Player.name, SpawnManager.PlayersSpawn.SpawnList[SpawnPnt].position, Quaternion.identity,0);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612160214im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
main Camera Not Getting activeated 0 Answers
Multiplayer Camera Rotation On Client 0 Answers
How can I change the viewport rect of two active cameras at runtime? - Splitscreen Multiplayer 1 Answer
Limit Z axis rotation on main camera (BUG?) 0 Answers
Distance lens flare jittering everywhere 0 Answers