- Home /
Player Won't Instantiate with Photon Unity Network [PUN]
Hello! I am having the problem that my player won't instantiate once I am connected to the server.
The console shows that the start and update work, but not my two other voids.
Here is my script for the player :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking;
public class PlayerNetwork : MonoBehaviour {
[SerializeField] private GameObject playerCamera;
[SerializeField] private MonoBehaviour[] PlayerControlScripts;
private PhotonView photonView;
private void Start() {
photonView = GetComponent<PhotonView> ();
Initialize ();
}
private void Initialize() {
if (photonView.isMine) {
} else {
playerCamera.gameObject.SetActive (false);
foreach (MonoBehaviour m in PlayerControlScripts) {
m.enabled = false;
}
}
}
}
Here is my script for the Network :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class PhotonNetworkManager: Photon.MonoBehaviour {
[SerializeField] private Text connectText;
[SerializeField] private Transform SpawnPoint;
[SerializeField] private GameObject Player;
[SerializeField] private GameObject LobbyCamera;
// Use this for initialization
void Start () {
PhotonNetwork.ConnectUsingSettings("6.7");
Debug.Log ("startWorks");
}
public virtual void OnJoinedLobby() {
Debug.Log ("Connected : Affirmative");
Debug.Log ("OnJoinedLobby Works");
PhotonNetwork.JoinOrCreateRoom ("New",null,null);
}
public virtual void OnJoinedRoom () {
PhotonNetwork.Instantiate (Player.name, SpawnPoint.position, SpawnPoint.rotation, 0);
Debug.Log ("OnJoinedRoom Works");
LobbyCamera.SetActive (false);
}
// Update is called once per frame
private void Update () {
connectText.text = PhotonNetwork.connectionStateDetailed.ToString ();
Debug.Log ("Update Works");
}
}
Thanks in advance. I f you have any other questions, feel free to ask!
Hi,
when do you call PhotonNetwork.Instantiate(...)? The easiest use case is to use the OnJoinedRoom callback for instantiating the player's character.
Thank you so much for the reply, I totally forgot to add the other script, so in an edit, I added it to my answer.
Your answer
Follow this Question
Related Questions
Photon Network instantiate problem when Master changes 0 Answers
How to network a large map with 4000+ movable objects using Photon Unity Networking? 1 Answer
How to make rapid fire with photon unity networking? 0 Answers
Photon Cloud, Multiplayer Damage script 0 Answers
Networking - Move all players to a position? (Photon) 1 Answer