SOMEBODY SAVEEE MEEEE!

Options

Hey guys! How are you? Can someone save me? I will be forever grateful.

The question is: How to activate/make visible a child GameObject inside an Instantiated GameObject for all Players?

Thanks in advance. My code:

public class CharSelect : MonoBehaviourPun, IPunObservable
{
  public GameObject[] characterPrefabs;
  public int selectedCharacter;
  public PhotonView pv;
  public void Start()
  {
    selectedCharacter = PlayerPrefs.GetInt("selectedCharacter");
    if (pv.IsMine)
    {
      pv.RPC("SelectChar", RpcTarget.Others);
      characterPrefabs[selectedCharacter].SetActive(true);
    }
  }

  [PunRPC]
  public void SelectChar()
  {
    characterPrefabs[selectedCharacter].SetActive(true);
  }

  public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
  {
    if(stream.IsWriting)
    {
      stream.SendNext(characterPrefabs[selectedCharacter].activeSelf);
    }
    if (stream.IsReading)
    {
      characterPrefabs[selectedCharacter].SetActive((bool)stream.ReceiveNext());
    }
  }

Comments

  • Tobias
    Options

    You could use the Instantiation Data. This is an optional parameter for PN.Instantiate and the value can be used in OnPhotonInstantiate. This is useful when this is a one-time setting.