- Home /
Photon wont sync for the masterclient.
I am trying to make this box so that only one player can use it at a time. Now this works if a client that is NOT the master client tries to open it when the master client has it open, but if the other client has it open the bool isn't synced to the master client. I have been stumped for like 5 hours and i need this to keep working. Please help.
The thing for changing the chest opened bool is on another script.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Inv_Man : MonoBehaviour {
public GameObject ChestOpener;
public bool Chestopen= false;
//armour
public GameObject LHelmObject;
public bool LHelmObjAct = false;
public GameObject LChestObject;
public bool LChestObjAct = false;
public GameObject LLegsObject;
public bool LLegsObjAct = false;
public GameObject LBootsObject;
public bool LBootsObjAct = false;
public GameObject IHelmObject;
public bool IHelmObjAct = false;
public GameObject IChestObject;
public bool IChestObjAct = false;
public GameObject ILegsObject;
public bool ILegsObjAct = false;
public GameObject IBootsObject;
public bool IBootsObjAct = false;
//spells
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if (stream.isWriting) {
stream.SendNext (Chestopen);
stream.SendNext (LHelmObjAct);
stream.SendNext (LChestObjAct);
stream.SendNext (LLegsObjAct);
stream.SendNext (LBootsObjAct);
stream.SendNext (IHelmObjAct);
stream.SendNext (IChestObjAct);
stream.SendNext (ILegsObjAct);
stream.SendNext (IBootsObjAct);
} else {
Chestopen = (bool)stream.ReceiveNext();
LHelmObjAct = (bool)stream.ReceiveNext();
LChestObjAct = (bool)stream.ReceiveNext();
LLegsObjAct = (bool)stream.ReceiveNext();
LBootsObjAct = (bool)stream.ReceiveNext();
IHelmObjAct = (bool)stream.ReceiveNext();
IChestObjAct = (bool)stream.ReceiveNext();
ILegsObjAct = (bool)stream.ReceiveNext();
IBootsObjAct = (bool)stream.ReceiveNext();
}
}
void Start () {
LHelmObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("L_Hat").gameObject;
LChestObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("L_Chest").gameObject;
LLegsObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("L_Legs").gameObject;
LBootsObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("L_Boot").gameObject;
IHelmObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("I_Hat").gameObject;
IChestObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("I_Chest").gameObject;
ILegsObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("I_Legs").gameObject;
IBootsObject = GameObject.Find("UI").transform.FindChild("BoxPanel").FindChild("Whitepanel").FindChild("I_Boots").gameObject;
//buttonlisteneradds
LHelmObject.GetComponent<Button>().onClick.AddListener(LHelmButton);
LChestObject.GetComponent<Button>().onClick.AddListener(LChestButton);
LLegsObject.GetComponent<Button>().onClick.AddListener(LLegsButton);
LBootsObject.GetComponent<Button>().onClick.AddListener(LBootButton);
IHelmObject.GetComponent<Button>().onClick.AddListener(IHelmButton);
IChestObject.GetComponent<Button>().onClick.AddListener(IChestButton);
ILegsObject.GetComponent<Button>().onClick.AddListener(ILegsButton);
IBootsObject.GetComponent<Button>().onClick.AddListener(IBootsButton);
//contentchoosing
if (Random.value < 0.5f) {
LHelmObjAct = true;
}
else {
LHelmObjAct = false;
}
if (Random.value < 0.5f) {
LChestObjAct = true;
}
else {
LChestObjAct = false;
}
if (Random.value < 0.5f) {
LLegsObjAct = true;
}
else {
LLegsObjAct = false;
}
if (Random.value < 0.5f) {
LBootsObjAct = true;
}
else {
LBootsObjAct = false;
}
if (Random.value < 0.5f) {
IHelmObjAct = true;
}
else {
IHelmObjAct = false;
}
if (Random.value < 0.5f) {
IChestObjAct = true;
}
else {
IChestObjAct = false;
}
if (Random.value < 0.5f) {
ILegsObjAct = true;
}
else {
ILegsObjAct = false;
}
if (Random.value < 0.5f) {
IBootsObjAct = true;
}
else {
IBootsObjAct = false;
}
}
public void UPDATECONTENTS(){
if (LHelmObjAct == true) {
LHelmObject.SetActive (true);
} else {
LHelmObject.SetActive (false);
}
if (LChestObjAct == true) {
LChestObject.SetActive (true);
} else {
LChestObject.SetActive (false);
}
if (LLegsObjAct == true) {
LLegsObject.SetActive (true);
} else {
LLegsObject.SetActive (false);
}
if (LBootsObjAct == true) {
LBootsObject.SetActive (true);
} else {
LBootsObject.SetActive (false);
}
if (IHelmObjAct == true) {
IHelmObject.SetActive (true);
} else {
IHelmObject.SetActive (false);
}
if (IChestObjAct == true) {
IChestObject.SetActive (true);
} else {
IChestObject.SetActive (false);
}
if (ILegsObjAct == true) {
ILegsObject.SetActive (true);
} else {
ILegsObject.SetActive (false);
}
if (IBootsObjAct == true) {
IBootsObject.SetActive (true);
}else{
IBootsObject.SetActive (false);
}
}
//spells
//armour
public void LHelmButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipLHelm();
LHelmObjAct = false;
UPDATECONTENTS ();
}
public void LChestButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipLChest();
LChestObjAct = false;
UPDATECONTENTS ();
}
public void LLegsButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipLLegs();
LLegsObjAct = false;
UPDATECONTENTS ();
}
public void LBootButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipLBoots();
LBootsObjAct = false;
UPDATECONTENTS ();
}
public void IHelmButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipIHelm();
IHelmObjAct = false;
UPDATECONTENTS ();
}
public void IChestButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipIChest();
IChestObjAct = false;
UPDATECONTENTS ();
}
public void ILegsButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipILegs();
ILegsObjAct = false;
UPDATECONTENTS ();
}
public void IBootsButton(){
ChestOpener.GetComponent<PlayerHealth> ().equipIBoots();
IBootsObjAct = false;
UPDATECONTENTS ();
}
}
`
Hi,
is this script added to the PhotonView's observed components?
Answer by achitimallix0102316 · Dec 24, 2018 at 11:02 PM
Hi, I am using PhotonPUN and Unity.. I have a scene where multiple players can join, and interact with some objects in the scene. All these intractable objects are PhotonView Objects, that are supposed to sync both Position and Rotation.
Both the Clients are able to see these objects, that I spawn later. But the update of Transform(Pos,Rot) is only working from Master to Non-Master clients, But when a non Master client moves these objects, the Master does not see the updates. These PhotonView objects are in the same Resources folder as the PlayerPrefabs.
Any thing that is attached to PlayerPrefab is visible to both clients.. Anything that is spawned and added using the PhotonNetwork.Instantiate(prefabName, childTransform.position, randAng, 0) are only syncing from Master to other clinet but not vice versa.
My problem is related to are similar to yours.. Have you found the solution to this? If so please let me know..
Your answer
Follow this Question
Related Questions
Switching weapons in PhotonNetwork 1 Answer
Photon Network instantiate problem when Master changes 0 Answers
Can i Call Additive Scene On Network 1 Answer
Photon network problem 2 Answers