NOTICE: This will need the NetworkPlayerSpawner from the code in the photon Tab if your using photon VR it wont work :)
using System.Collections;
using System.Collections.Generic;
using Photon.Pun;
using UnityEngine;
using UnityEngine.XR;
public class Cosmetic : MonoBehaviour
{
public NetworkPlayerSpawner networkPManager;
private PhotonView photonView;
private float hapticWaitSeconds = 0.05f;
public bool enableButton;
public string CosmeticName;
private void Update()
{
if (PhotonNetwork.InRoom)
{
if (networkPManager.isPlayerSpwaned)
{
photonView = networkPManager.spawnedPlayerPrefab.GetComponent<PhotonView>();
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "LeftHand Controller" || other.gameObject.name == "RightHand Controller")
{
if (enableButton)
photonView.RPC("EnableCosmetic", RpcTarget.AllBuffered, CosmeticName);
else
photonView.RPC("DisableCosmetic", RpcTarget.AllBuffered, CosmeticName);
}
}
}
using System.Collections.Generic;
using Photon.Pun;
using UnityEngine;
public class PlayerCosmetics : MonoBehaviour
{
public List<GameObject> Cosmetics;
[PunRPC]
private void EnableCosmetic(string cosmeticName)
{
for (int i = 0; i < Cosmetics.Count; i++)
{
if (Cosmetics[i].name == cosmeticName)
{
Cosmetics[i].SetActive(true);
}
}
}
[PunRPC]
private void DisableCosmetic(string cosmeticName)
{
for (int i = 0; i < Cosmetics.Count; i++)
{
if (Cosmetics[i].name == cosmeticName)
{
Cosmetics[i].SetActive(false);
}
}
}
}
in your NetworkPlayerSpawner you have to add this to it
public bool isPlayerSpwaned;
then in the void OnJoinedRoom() add this
isPlayerSpwaned = true;
and then for OnLeftRoom() add this
isPlayerSpwaned = false;
spawnedPlayerPrefab THIS MUST BE A PUBLIC NOT PRIVATE!!!