Serializing the object states (visible / invisible)?

ruse
ruse
So there are character objects, in the beginning, i want them to be visible or invisible through a random variable and serialize it to everyone. For example, if the variable is equal to 1, the first character should be visible and the other one should be invisible. The avatars are for setting the animator avatar of the character.

The code is below;

Animator anim;
public Avatar char1;
public Avatar char2;
public GameObject char1Obj;
public GameObject char2Obj;

void Start () {

        anim = GetComponent<Animator>();
        

        randomChar = Random.Range(1, 3);

        if (randomChar == 1)
        {
            char1Obj.SetActive(true);
            char2Obj.SetActive(false);
            anim.avatar = char1;
            playerRole.mannequin = char1Obj;
        }
        else
        {
            char2Obj.SetActive(true);
            char1Obj.SetActive(false);
            anim.avatar = char2;
            playerRole.mannequin = char2Obj;
        }

    } 

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext(char1Obj.activeSelf);
            stream.SendNext(char2Obj.activeSelf);
        }
        else
        {
            char1Obj.SetActive((bool) stream.ReceiveNext());
            char2Obj.SetActive((bool) stream.ReceiveNext());
        }
    }


-----------------------------------------------------------------------------------------------------------------------------------------------------

That should work i guess but it doesn't, the states are not serialized.
So, any idea to fix this issue?

Best Answer

Answers

  • following.. I am trying to achieve same goal