Inventory and Item Pickup Script Help [C#]
Options
Hello,
I have a item pickup script that add's an item to the player's inventory when the player is over the object in game and clicks the left mouse button how it does this is by adding an item to an array and then deleting the object. This script works just fine when only one person is logged in on the server but if two people are on i get an error on only one of the clients:
Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who has left: View (0)1002 on lumber(Clone)
and then the other client can take and remove the objects just fine.
I read about photon not letting clients destroy objects but is there anyway around this?
another small error i get is that when two people are joined it randomly gives the player two lumber instead of one.
Any idea's?
Thanks,
Joseph
I have a item pickup script that add's an item to the player's inventory when the player is over the object in game and clicks the left mouse button how it does this is by adding an item to an array and then deleting the object. This script works just fine when only one person is logged in on the server but if two people are on i get an error on only one of the clients:
Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who has left: View (0)1002 on lumber(Clone)
and then the other client can take and remove the objects just fine.
I read about photon not letting clients destroy objects but is there anyway around this?
another small error i get is that when two people are joined it randomly gives the player two lumber instead of one.
Any idea's?
Thanks,
Joseph
0
Comments
-
To network-destroy object you must call PhotonNetwork.Destroy from client which created that object.
Another option is to send 'destroy' RPC to all clients and call non-network GameObject.Destroy method on every client.
See \Assets\Photon Unity Networking\UtilityScripts\OnClickDestroy.cs script for reference (when DestroyByRpc = true).another small error i get is that when two people are joined it randomly gives the player two lumber instead of one.0 -
Thanks for replying,
I currently use PhotonNetwork.Destroy and i still get the 'Network Remove' error, I will look into sending a destroy RPC.
Shall I ask any further questions on the same topic here or in a new thread?
Thanks,
Joseph0 -
Hello,
Thanks so much! I got it to work using RPC's but i have another question!
How my, 'give the player lumber' script works is by sending a message to the player to add lumber, here is the code:void CollectItem(){ if(Collect == true && Input.GetMouseButtonDown(0)){ clicks += 1; player.SendMessage("Add", material); } if(clicks == maxClicks){ this.photonView.RPC("DestroyResource", PhotonTargets.AllBuffered); } }
my problem is the script doesn't know which player to send the Add command to. How would I tell the script who the nearest player is and send the add command to that player? Or maybe there is another way to do it.
Thanks so much for the first bit of help!
Joseph0 -
Hello,
One More Question:
I have this code which PhotonNetwork.Instantiate's my lumber at its spawn points but when another player joins it spawns another set of lumber and i can't figure out why!
here's the code:public class ResourceSpawn : MonoBehaviour { Vector3 SpawnPoint; bool ResourcesSpawned = false; public GameObject ResourceSpawnPoint; // Use this for initialization void Start () { SpawnPoint = ResourceSpawnPoint.transform.position; } // Update is called once per frame void Update () { } void OnJoinedRoom(){ if(ResourcesSpawned == false){ PhotonNetwork.Instantiate ("lumber", SpawnPoint, Quaternion.identity, 0); ResourcesSpawned = true; } else if (ResourcesSpawned == true){ } } }
0 -
my problem is the script doesn't know which player to send the Add command to. How would I tell the script who the nearest player is and send the add command to that player? Or maybe there is another way to do it.when another player joins it spawns another set of lumber0
-
Hello,
Thanks for the help, I will try out the new methods now
Thanks,
Joseph0 -
How would I use PhotonNetwork.player? If i change the line, player.SendMessage("Add", material); to PhotonNetwork.player.SendMessage("Add", material);
It comes up with this error:
PhotonPlayer does not contain a definition for SendMessage.
I also tried to define player as, player = PhotonNetwork.player
but that comes up with the error, Cannot convert PhotonPlayer to UnityEngine.GameObject - same for transform aswell
What am i doing wrong?
EDIT: PhotonNetwork.InstantiateSceneObject works awesome! Thanks so much
Thanks,
Joseph0 -
I have no idea what is 'player' in your code.
In PUN, PhotonNetwork.player is plain object (not GameObject) which represents your player in currently joined room. You can use it for storing various player data via custom properties. They will be available automatically on all joined clients. See PhotonPlayer.SetCustomProperties / PhotonPlayer.customProperties and PhotonNetwork.playerList0 -
Hello,
player is the players game object which I am trying to access. How would I go about using setCustomProperties for my inventory? would I set a custom property when I pick-up an object then read the list of custom properties in my inventory script?
Thanks,
Joseph0 -
would I set a custom property when I pick-up an object then read the list of custom properties in my inventory script0