How to switch turns ?
Options
Comments
-
If you don't mind, I would suggest you use Unity and Photon Unity Networking with that. In there, we implemented "RPC"s and those are very simple to use and a fine fit for your turn-based game.
In the LoadBalancing API you can use OpRaiseEvent and or set a Custom Property for your room. The first would send your turn, the second would make the server remember that your turn was done.0 -
Tobias wrote:If you don't mind, I would suggest you use Unity and Photon Unity Networking with that. In there, we implemented "RPC"s and those are very simple to use and a fine fit for your turn-based game.
In the LoadBalancing API you can use OpRaiseEvent and or set a Custom Property for your room. The first would send your turn, the second would make the server remember that your turn was done.
Thank you for the reply.I'm using OnPhotonSerializeView but I'm not sure if it works.Can you look at the code tell me if I have mistakes.
[code2=csharp]using UnityEngine;
using System.Collections;
public class SwitchTurns : Photon.MonoBehaviour {
public static bool Player1Turn;
private static bool Player2Turn;
private PhotonView photonView;
private bool receiveData;
private bool sendData;
// Use this for initialization
void Start () {
if(PhotonNetwork.isMasterClient){
Shooting.isMyTurn=true;
}
else{
Shooting.isMyTurn=false;
}
}
// Update is called once per frame
void Update () {
sendData=Shooting.isMyTurn;
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
stream.SendNext((bool)sendData);
Debug.Log("Streaming!!!");
}
else
{
//Network player, receive data
receiveData = (bool)stream.ReceiveNext();
Debug.Log(receiveData);
}
}
void switchTurns(){
if(Shooting.isMyTurn==true){
//enable the script FirstPersonControls
Debug.Log("It's my turn!");
}
else{
//disable the script
Debug.Log("Not my turn!");
}
if(Player2Turn){
//enable the script FirstPersonControls
}
else{
//disable the script
}
}
}[/code2]
So the idea is if I'm the masterclient I'll be the first one.When I finish my turn isMyTurn will be false and I send it to the other player .But it doesn't show me "Its my turn" and streaming.0 -
You should read the Marco Polo Tutorial and make sure your script is on a GO together with a PhotonView. Drag and drop the script on said GO to the "Observed" field of the PV and try again.
http://doc.exitgames.com/photon-cloud/M ... o_Tutorial0 -
Thanks Tobias it worked0