- Home /
Question by
zak666 · May 06, 2016 at 12:53 AM ·
networkingphotonscript errorconnection
error spawning player says I'm not connected when photon connects and puts me in a room
ok so i connect yup join lobby yup join room yup. I'm in me game, tho when i go to spawn a player it gives me an error I'm not connected? (these are both on me missioncontroll empty game object yes it has network view assigned to it.)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Missioncontroll : Photon.MonoBehaviour {
const string VERSION = "0.1";
public string roomName = "GameRoom";
public float Timer = 500f; // amount of time before game with bots.
private bool inGame = false;
public NetworkView nView;
public static int IamPlayer = 0;
public int Maptoload = 0;
public GameObject ToggleOnOff;
public GameObject ToggleOnOff2;
//score controllers
public GameObject Player1;
public GameObject Player2;
public GameObject Player3;
public GameObject Player4;
public GameObject Player5;
//number of players in room (ICON)
public GameObject GameObjectPlayerIcon1;
public GameObject GameObjectPlayerIcon2;
public GameObject GameObjectPlayerIcon3;
public GameObject GameObjectPlayerIcon4;
public GameObject GameObjectPlayerIcon5;
public GameObject map1;
//TimerDisplay
public Text Timertext;
//------------------------------------------------------------------------------------------------------------
void Awake() {
Network.minimumAllocatableViewIDs = 500;
}
void Start(){
nView = GetComponent<NetworkView>();
Connect ();
}
//------------------------------------------------------------------------------------------------------------
void Connect(){
PhotonNetwork.ConnectUsingSettings (VERSION);
}
//------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
void OnJoinedLobby () {
Debug.Log ("Joined Lobby");
RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 5 };
PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
}
//--------------------------------------------------------------------------------------------------------------
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
//--------------------------------------------------------------------------------------------------------------
void OnJoinedRoom() {
Debug.Log ("Joined Room");
BotGameController.NumberofPlayers -= 1; //(add a player to the player counter)
if (PhotonNetwork.countOfPlayers == 0){
Player1.SetActive (true);
GameObjectPlayerIcon1.SetActive(true);
}
if (PhotonNetwork.countOfPlayers == 1){
Player1.SetActive (true);
IamPlayer = 1;
}
if (PhotonNetwork.countOfPlayers == 2){
Player2.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer2", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 2;
}
if (PhotonNetwork.countOfPlayers == 3){
Player3.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer3", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 3;
}
if (PhotonNetwork.countOfPlayers == 4){
Player4.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer4", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 4;
}
if (PhotonNetwork.countOfPlayers == 5){
Player5.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer5", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 5;
}
}
//every time a player joins tell others in the room to set icons.
//------------------------------------------------------------------------------------------------------------
[PunRPC]
void Haveplayer1(){
GameObjectPlayerIcon1.SetActive(true);
}
//------------------------------------------------------------------------------------------------------------
[PunRPC]
void Haveplayer2(){
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
}
//------------------------------------------------------------------------------------------------------------
[PunRPC]
void Haveplayer3(){
GameObjectPlayerIcon1.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon3.SetActive(true);
}
[PunRPC]
void Haveplayer4(){
GameObjectPlayerIcon1.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon3.SetActive(true);
GameObjectPlayerIcon4.SetActive(true);
}
[PunRPC]
void Haveplayer5(){
GameObjectPlayerIcon1.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon3.SetActive(true);
GameObjectPlayerIcon4.SetActive(true);
GameObjectPlayerIcon5.SetActive(true);
}
//------------------------------------------------------------------------------------------------------------
void mapselectselect (){
//randomrange (mapselect) (consistent with all players so they all end up in same map.)
map1.SetActive(true);
ToggleOnOff.SetActive (false);
ToggleOnOff2.SetActive (true);
}
//------------------------------------------------------------------------------------------------------------
void LateUpdate (){
//loadmap automaticly after timer regadless of player count.
Timer -= 1;
if(Timer <1){
mapselectselect();
}
Timertext.text = "" + Timer.ToString();
}
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
{
if (stream.isWriting) {
// We own this player: send the others our data
stream.SendNext (inGame);
} else {
// Network player, receive data
this.inGame = (bool)stream.ReceiveNext ();
}
}
}
}
//------------------------------------------------------------------------------------------------------------
public class StarfighterSelet : MonoBehaviour {
public GameObject Fighter01;
public GameObject Fighter02;
public GameObject Camera1;
public GameObject ShipSelectGUI;
public GameObject GameGUI;
public Transform SpawnPlayer;
public void Fighter01Select () {
ShipSelectGUI.SetActive (false);
GameGUI.SetActive (true);
Network.Instantiate(Fighter01, SpawnPlayer.position, SpawnPlayer.rotation, 1);
}
public void Fighter02Select () {
ShipSelectGUI.SetActive (false);
GameGUI.SetActive (true);
Network.Instantiate(Fighter02, SpawnPlayer.position, SpawnPlayer.rotation, 1);
}
}
Comment
Your answer
Follow this Question
Related Questions
Failed Network.Instantiate because we are not connected. (when logs show i connect and joined room.) 0 Answers
Client Disconnect with message “Peer Created” - PUN 0 Answers
PhotonNetwork.Instantiate is not "buffered" 0 Answers
[Edited]How To establish a mmo game By using Bluetooth 1 Answer
Photon Networking: LocalScale transform doesn't work 1 Answer