I have little problem with photon network player spawning. When i join game it will spawn forever players. I don’t know why it is looping…
using System;
using UnityEngine;
using System.Collections;
public class NetworkManager1 : MonoBehaviour{
private bool networkBIN;
private bool joinedLobby;
public string roomName;
void Start(){
networkBIN = false;
}
void Update()
{
if (joinedLobby == true)
{
SpawnMyPlayer();
}
}
void OnGUI(){
if (networkBIN == false){
if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2,100, 50), "Network")){
networkBIN = true;
ConnectToLobby();
}
}
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
if (joinedLobby == true)
{
roomName = GUI.TextField(new Rect(Screen.width / 2, Screen.height / 2, 100, 50), roomName, 25);
if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2 - 50, 100, 50), "Create"))
{
CreateRoom(roomName);
}
if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2 + 50, 100, 50), "Join Room"))
{
PhotonNetwork.JoinRoom("rN");
}
}
}
void ConnectToLobby(){
PhotonNetwork.ConnectUsingSettings("1.0");
}
void OnJoinedLobby(){
joinedLobby = true;
}
void CreateRoom(String rN)
{
PhotonNetwork.CreateRoom("rN");
}
void OnPhotonJoinRoomFailed()
{
}
void SpawnMyPlayer()
{
PhotonNetwork.Instantiate("Player", new Vector3(0f, 0.5f, 0f), Quaternion.identity, 0);
}
}