Hello, I’m making a simple pong clone with multiplayer, I used Unity Networking but it had problems with NAT punchthrough so I switched to PUN. Could I have any suggestions for scripts?
This is what I currently have, it doesn’t work as far as I’m aware and PUN slows down to a crawl and kills my internet when I’ve made a build and play it through the .exe so I can’t really test it:
using UnityEngine;
using System.Collections;
public class ConnectRandom : MonoBehaviour {
// Use this for initialization
public float spawnpos;
string curstage;
private const string roomName = "Room";
RoomInfo[] roominfo;
private void Awake(){
PhotonNetwork.logLevel = PhotonLogLevel.Full;
Debug.Log("Awake!");
if(!PhotonNetwork.connected){
PhotonNetwork.ConnectUsingSettings("1.0");
curstage = "Connecting...";
Debug.Log("Connecting...");
}
}
void OnJoinedLobby(){
Debug.Log("Joined the Lobby...");
// JoinGame ();
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log("Couldn't join a random room");
curstage = "Random join failed";
RoomInfo[] rinfo = PhotonNetwork.GetRoomList();
for(int i = 0; i < rinfo.Length; i++)
Debug.Log(rinfo[0]);
curstage = "Creating a room";
Debug.Log("Creating a room!");
PhotonNetwork.CreateRoom(null); // Doesn't move past this point as far as I can tell
}
void OnPhotonCreateGameFailed(){
curstage = "Failed to create game";
Debug.Log("Failed to create a game!");
}
void OnJoinedRoom(){
if(PhotonNetwork.isMasterClient)
PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable(){{"ScoreServer", 0}, {"ScoreClient", 0}});
if(PhotonNetwork.isMasterClient)
spawnpos *= -1f;
Vector3 spawnvec = new Vector3(spawnpos, 0f, 0f);
GameObject go = (GameObject)PhotonNetwork.Instantiate("Playerone", spawnvec, Quaternion.identity, 0);
go.GetComponent<Paddlemove>().enabled = true;
Debug.Log ("Joined a Game!");
curstage = "Joined game";
Debug.Log((int)PhotonNetwork.room.customProperties["ScoreServer"] + " " + (int)PhotonNetwork.room.customProperties["ScoreClient"]);
}
void OnCreateRoom(){
curstage = "Created a room";
Debug.Log("Created a Room!");
}
void OnGUI(){
GUI.Label(new Rect(0f,0f,100f,20f), curstage);
}
}
Help would be appreciated.