現在UnityでPUNを利用して対戦型カードゲームを製作しております。
両プレイヤーがターンエンドボタンを押したらゲームのモードを変える、という処理を実装したいと思っています。
Player1、Player2それぞれがボタンを押した時_isPush、_isPush2をTrueにし、両方がTrueになったらモードが変わる、という風に記述しているのですが、どうやらPlayer1側では変数の送信のみ、Player2側では変数の受信のみしか行えないということがわかりPlayer2側でしかモードが変わりませんでした。
こちらはどのようにしたらPlayer1側でもモードの変更を同期できるようになりますでしょうか。
現在オーナーの切り替えをしてPlayer2側でも送信を行えないか試しているのですが、
if (photonView.ownershipTransfer != OwnershipOption.Request)
{
Debug.LogError("OwnershipTransferをRequestに変更してください。");
}
を通ってしまい、難航している状態です。
何かアドバイスいただけますと幸いです。
※下記スクリプトのTurnEnd()、OnPhotonSerializeView()、RequestOwner()の部分です。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class GameManager : Photon.MonoBehaviour { 6 7 private PhotonView photonView; 8 9 public HandList handList; 10 [SerializeField] private string m_resourcePath = "Card"; 11 [SerializeField] Transform[] spawnPoints; 12 13 bool _isPush = false; 14 bool _isPush2 = false; 15 16 public ClassList classList; 17 18 void Start() 19 { 20 photonView = GetComponent<PhotonView>(); 21 } 22 23 //カードの生成 24 public void SpawnObject(int playerNum, int handNum) 25 { 26 for (int i = 0; i < handNum; i++) 27 { 28 GameObject card = PhotonNetwork.Instantiate(m_resourcePath, spawnPoints[playerNum].transform.position, spawnPoints[playerNum].rotation, 0); 29 handList.ListAdd(card, playerNum); 30 CardSetting cardSetting = card.GetComponent<CardSetting>(); 31 int _cardNum = (int)Random.Range(0f, 5f); //カードの種類だけランダム生成 32 cardSetting.cardIndex = _cardNum; 33 cardSetting.ToggleFace(0); 34 } 35 } 36 37 public void TurnEnd( ) { 38 if( PhotonNetwork.player.ID == 1 ) { 39 _isPush = true; 40 Debug.Log("1クリックした" ); 41 } else { 42 _isPush2 = true; 43 Debug.Log( "2クリックした" ); 44 } 45 46 if( _isPush && _isPush2 ) { 47 Debug.Log("ターンチェンジ" ); 48 classList.modeManager.mode_type++; 49 } 50 51 RequestOwner(); 52 } 53 54 void OnPhotonSerializeView( PhotonStream stream, PhotonMessageInfo info ) { 55 if ( stream.isWriting ) { 56 //データの送信 57 stream.SendNext( _isPush ); 58 stream.SendNext( _isPush2 ); 59 Debug.Log("送信"); 60 } else { 61 //データの受信 62 this._isPush = ( bool )stream.ReceiveNext( ); 63 this._isPush2 = ( bool )stream.ReceiveNext( ); 64 Debug.Log("受信"); 65 } 66 } 67 68 private void RequestOwner() 69 { 70 if (photonView.ownerId != PhotonNetwork.player.ID) 71 { 72 if (photonView.ownershipTransfer != OwnershipOption.Request) 73 { 74 Debug.LogError("OwnershipTransferをRequestに変更してください。"); 75 } 76 else 77 { 78 photonView.RequestOwnership(); 79 } 80 } 81 } 82 83} 84
あなたの回答
tips
プレビュー