Question by
ozeol · Jun 20, 2021 at 09:03 AM ·
instantiatephotonrpcinitialize
Why the prefab does not instantiate on both player's views on the Photon Network?
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;
}
}
}
Comment
Your answer