Why the prefab does not instantiate on both player's views on the Photon Network?

jsm
jsm
I want the dice prefab to be visible to both players. Currently the dice are visible separately in the views but not together in the same view. Can someone please point out the issue? My PlayerController script:

public GameObject myDiceObj;

void Start()
{
GameObject Canv = GameObject.Find("Canvas");
myDice = "TwentyLeft";
GameObject dice = PhotonNetwork.Instantiate(myDice, transform.position, Quaternion.identity);
dice.transform.parent = Canv.transform;
dice.GetPhotonView().RPC("Initialize", RpcTarget.Others, false);
dice.GetPhotonView().RPC("Initialize", photonPlayer, true);

myDiceObj.transform.GetChild(0).gameObject.GetComponent<Image>().enabled = true;
}

The dice Monobehaviour script:

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

public class Dice : MonoBehaviourPun
{

[PunRPC]
void Initialize(bool isMine)
{

if (isMine)
{
PlayerController.me.myDiceObj = this.gameObject;

}
else
{
GameManager.instance.GetOtherPlayer(PlayerController.me).myDiceObj = this.gameObject;

}
}
}

Answers

  • because you'r dsoing it in start and its too fast fam. chill on that shit until you get both players happyily into room.

    Use the magic callback:

    public class PlayerScript : MonoBehaviourPun, IPunInstantiateMagicCallback
    {

    void IPunInstantiateMagicCallback.OnPhotonInstantiate(PhotonMessageInfo info)
    {
    if (info.photonView.IsMine)
    {
    base.GetComponent<HasControl>().ChangeControl(true);
    this.Initialize(true);
    return;
    }

    this.Initialize(false);

    }

    Initialize(bool isLocal)
    {
    DoShitHere..
    }