On entering a trigger zone of an object a message is displayed to the player (which is found by tag). If the player then presses the pickup button, the item is added to their inventory. It works fine in single-player games.
When I use PUN (Photon Networking) though it displays it to all players (as all player's script detect the event) and all players can pickup the item. How I can fix this problem?
I believe fixing this piece will enable me to understand how to fix everything else:
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
displayMessage = true;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Player")
{
displayMessage = false;
}
}
bool stop = false;
void OnGUI()
{
if (displayMessage)
{
if (GameObject.FindGameObjectWithTag("UInventory").GetComponent<UInventory>().inventoryMode == "Weight")
{
GUI.Label(new Rect((Screen.width/2)-200, (Screen.height/2)-30, 200, 45), "Press " + pickUpItem.ToString() + " To Take " + itemName + "(" + itemWeight + "kg)");
}
else
{
GUI.Label(new Rect((Screen.width/2)-200, (Screen.height/2)-30, 200, 45), "Press " + pickUpItem.ToString() + " To Take " + itemName);
}
}
}
Trigger code should be executed only if client owns network object. Use 'isMine' property of 'PhotonView' component of the object to check if this is true.