###困っていること
一人のユーザが建ててもうひとりのユーザーが入るとプログラムが以下のようなエラーを吐いて停止する。
lang
1The observed monobehaviour (PhotonManager) of this PhotonView does not implement OnPhotonSerializeView()! 2UnityEngine.Debug:LogError(Object)
###環境
Unity 2018 1.3.f1
OS windows10
通信方式 TCP
部屋を作る側がUnity Editorを使用し、buildしたexeファイルを入る側として使用
ResourceにPhotonManagerというオブジェクトを作り下記の2つのスクリプトをアタッチして、Asset直下のResourcesに格納済み。また、下記のスクリプト2つもResourcesに格納済み
###プログラムの内容
editor側が建てたあとにbuildしたexeファイルが入る。(お互いロビーに入るが、エディタ側が建てたルームに入れない。入ろうとしたところでエラーが出てくる。)
その後、buildしたexeファイルが変数をボタンでchange()を実行して変更。(ルームに入らずに何も接続していない状態での変更を確認)
editor側で変更を確認する。
PhotonManagerServer.csでルームの作成から接続までを行う
Arrow.csで変数同期。初期値は0だが、change()を押された際にarrow = 1000に変更して同期
###ソース
PhotonManagerServer.cs
lang
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class PhotonManagerServer : Photon.MonoBehaviour { 6 private string roomName = "sababeya"; 7 8 9 void OnJoinedLobby () 10 { 11 Debug.Log ("PhotonManager OnJoinedLobby"); 12 13 } 14 15 void OnJoinedRoom() { 16 Debug.Log ("PhotonManager OnJoinedRoom"); 17 } 18 19 public void ConnectPhoton(){ 20 PhotonNetwork.ConnectUsingSettings ("1.0"); 21 } 22 23 //ルーム作成 24 public void CreateRoom(){ 25 PhotonNetwork.CreateRoom(roomName); 26 } 27 28 public void joinroom() 29 { 30 PhotonNetwork.JoinRandomRoom(); 31 } 32 33}
Arrow.cs
lang
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class Arrow : Photon.MonoBehaviour 7{ 8 public int arrow = 0; 9 10 void OnPhotoSerializeView(PhotonStream stream, PhotonMessageInfo info) 11 { 12 if (stream.isWriting) 13 { 14 stream.SendNext(arrow); 15 Debug.Log("送信ナウ"); 16 } 17 else 18 { 19 this.arrow = (int)stream.ReceiveNext(); 20 Debug.Log("受信ナウ"); 21 } 22 } 23 24 void Update() 25 { 26 Debug.Log(arrow); 27 } 28 29 public void changer() 30 { 31 arrow = 1000; 32 } 33} 34
あなたの回答
tips
プレビュー