I am currently to to instantiate a box when the player drops it (using "PhotonNetwork.Instantiate"). Now this box, when the player drops it is given data about that box, in the form of an Enum and then distributes the value to the box. But, when the other client picks it up, the box has no values.
code:
[RPC] void dropItem(Item item){
Vector3 playerPos = this.transform.position;
Vector3 playerDirection = this.transform.forward;
Quaternion playerRotation = this.transform.rotation;
float spawnDistance = 1;
Vector3 spawnPos = playerPos + playerDirection*spawnDistance;
string itemname = item.itemName;
GameObject itemAsGameObject = (GameObject)PhotonNetwork.Instantiate("DroppedItem", spawnPos, playerRotation, 0);
itemAsGameObject.GetComponent<DroppedItem> ().item = item;
}
As you can see the client that drops the box has the values. but they arent being passed over to the other clients on the network. how can i fix this?
If you need the object within the level, try instantiating it as a scene object instead of the normal instantiation: PhotonNetwork.InstantiateSceneObject. Another thing is that you don't need to cast the instantiated object as GameObject, because photon already does that for you, it's not like normal instantiation.
Also, if you just need one box per gameroom, you'll gonna be able to reach a better performance if you create some logics to don't destroy the box when it collides with a player. Try desabling it somehow instead of destroying and restantiate it everytime. An idea is to turn enable = false of components like: Animator, SpriteRenderer, Colliders etc. Then, instead of instantiating it again when a player drops it, just turn on those components again, but don't forget to change the box's position as you are already doing.
;)