Bool value not Syncing across network using onPhotonSerializeView

58 Views Asked by At

My bool value changes to true when it enters a trigger, I want to sync this change across the network. Another script attached to a gameobject detects the change and prints to the console. I used these scripts but the change isn't reflecting across the network.

Script that sends updated bool value:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class Between_O_and_F_script : MonoBehaviourPun,IPunObservable
{
    // Start is called before the first frame update
    [SerializeField]
    public bool between_O_and_F;
    PhotonView view;
    void Start()
    {
        view = GetComponent<PhotonView>();
    }
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(between_O_and_F);
            
        }
        
    }


    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("entered between O and F");
        between_O_and_F = true;
        

    }
    private void OnTriggerExit(Collider other)
    {
        between_O_and_F = false;
        
    }
    

}

Script that receives updated bool value and does an action:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class Win_check_lense : MonoBehaviourPun,IPunObservable
{
    // Start is called before the first frame update
    private string currentpos = "";
    [SerializeField]
    public bool between_O_and_F;
    public bool Beyond_2F;
   
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        
        if (!stream.IsWriting)
        {
            between_O_and_F = (bool)stream.ReceiveNext();
            recbool();
          
            Debug.Log(between_O_and_F);
            
        }
    }

    void Start()
    {
        string lense = "convex";
        string[] positions = { "Object beyond 2F", "Object at 2F", "Object between F and 2F","Object between O and F"};
        string element = positions[Random.Range(0, positions.Length)];
        currentpos = element;

        
    }

    // Update is called once per frame
    void Update()
    {
       
    }
    private void recbool()
    {
        if (between_O_and_F == true)
        {

            Debug.Log("correct");


        }
        Debug.Log(between_O_and_F);
    }

}

I have photonview attached to the object, and it is observing the script that needs to observed.

Can someone help me out please?

0

There are 0 best solutions below