Hi guys. This is my first post at photonengine. Please excuse if i have posted this in the wrong section.
I have been working on unity for a few months now and have a basic understanding of the environment. Currently i am working on a multiplayer game and for that i am using Photon Unity Networking utility ( PUN intended :P ). This would be my first multiplayer game.
I have a room and a corresponding scene where all the players join and can roam around freely. What i want to do is to be able to touch/click on a player and start a battle with just that player ( I have the code for selecting objects using raycast and colliders but what that does is give me the object that i created locally using photon.instantiate to mimic the network players. )
The way i have decided on implementing this is to take myself and the target player to a different room ( battle room ) and load a new scene ( battle scene ) while the other players are still in the free roaming room / scene.
QUESTIONS:
(1) How can i select a specific network player and communicate with just that player to tell them that a match is about to start between that player and myself and make them join a different room with me?
(2) Does it make a difference if i load the battle scene before or after i join the battle room?
(3) How can i make the target player load the new scene and check over the network if their device has finished loading the new scene?I AM a Photon illiterate ( maybe even a Unity illiterate ) so please excuse if i annoy you.
I shall appreciate all answers.
EDIT: Here is the code i am using:
(Selecting opponent through touch )
if (Input.touchCount >= 1)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
touchStartPos = touch.position;
}
if (touch.phase == TouchPhase.Ended)
{
if (touch.position == touchStartPos)
{
Ray cursorRay = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if (Physics.Raycast(cursorRay, out hit, 1000.0f))
{
if (hit.transform.gameObject.tag == "opponent")
{
selectedOpponent = hit.transform.gameObject;
myObj = GameObject.FindGameObjectWithTag("MyObj");
string roomName = "" + myObj.gameObject.transform.name + selectedOpponent.gameObject.transform.name + (int) Random.Range(1,100) ;
myObj.GetComponent<PhotonView>().RPC("StartFight", PhotonTargets.All, myObj.GetComponent<PhotonView>().viewID.ToString(), selectedOpponent.GetComponent<PhotonView>().viewID.ToString(), roomName);
}
}
}
}
}
(StartFight RPC)
[PunRPC]
void StartFight( string pID , string oID , string roomName ) //pID = local player's viewID, oID = target player's viewID
{
foreach ( PhotonPlayer player in PhotonNetwork.playerList )
{
if (player.customProperties.ContainsValue(pID) )
{
PhotonNetwork.LeaveRoom();
PlayerPrefs.SetString("roomName", roomName);
StartCoroutine(newRoom(roomName));
}
else if ( player.customProperties.ContainsValue(oID) )
{
PhotonNetwork.LeaveRoom();
PlayerPrefs.SetString("roomName", roomName);
StartCoroutine(newRoom(roomName));
}
}
}
The issue here is that even though i am checking player's ID and only executing PhotonNetwork.LeaveRoom() for the player's whose ID is matched, it is making all the players leave the room.(newRoom CoRoutine)
IEnumerator newRoom ( string roomName )
{
PhotonNetwork.LoadLevel("Teset_Scene4");
yield return null;
}
This function is called when the new scene is loaded, here is where i attempt to join a new room
void JoinFightRoom ( )
{
if (!(PhotonNetwork.connected))
{
PhotonNetwork.ConnectUsingSettings(Constants.VERSION); // Constants.VERSION = "v0.0.1"
}
else
{
string roomName = PlayerPrefs.GetString("roomName");
RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 2 };
PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
}
}
The issue here is that it gives me the following error:
JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.