Help| Ball Materials in Networking
Ben1911
✭
Hello, I'm create my first game with Network (Photon Networking, Photon Server).
I created Menu and before Player join room he selects Ball to play with it. The ball is have Materials and after the selecting I save it to:
And after in the game (in the room), I do this:
The code works fine, but The Master (who created the room) sees the change of the Materials (to two Players), but The client (who connects to room) doesn't see it (He sees the default Material to himself and to the Master).
I have no idea what to do, anyone can tell me how i can fix that?
Sorry for my bad English.
Thanks!
I created Menu and before Player join room he selects Ball to play with it. The ball is have Materials and after the selecting I save it to:
Hashtable playerProps = new Hashtable {{"BallMaterial", renderer.material.name}}; PhotonNetwork.player.SetCustomProperties(playerProps);
And after in the game (in the room), I do this:
string materialName = PhotonNetwork.player.customProperties["BallMaterial"].ToString().Substring(0, 9); Material ballMaterial = Resources.Load(materialName, typeof(Material)) as Material; GameObject ball = PhotonNetwork.Instantiate("Sphere", GetRandomPoint(), spawnPoints[0].rotation, 0); ball.renderer.material = ballMaterial;
The code works fine, but The Master (who created the room) sees the change of the Materials (to two Players), but The client (who connects to room) doesn't see it (He sees the default Material to himself and to the Master).
I have no idea what to do, anyone can tell me how i can fix that?
Sorry for my bad English.
Thanks!
0
Comments
-
Only the master sees this, as only the master is actually calling PN.Instantiate().
When PUN creates some object because another client called Instantiate, it will also callvoid OnPhotonInstantiate(PhotonMessageInfo info) { }
on the GameObject's scripts. So put the material change in this method and add it to the prefab you instantiate.
Open the enum PhotonNetworkingMessage and take a look at the description in value OnPhotonInstantiate.
Hope that helps!0 -
Tobias wrote:Only the master sees this, as only the master is actually calling PN.Instantiate().
When PUN creates some object because another client called Instantiate, it will also callvoid OnPhotonInstantiate(PhotonMessageInfo info) { }
on the GameObject's scripts. So put the material change in this method and add it to the prefab you instantiate.
Open the enum PhotonNetworkingMessage and take a look at the description in value OnPhotonInstantiate.
Hope that helps!
But, It doesn't works fine. What happening now is when I select Ball (for example 'A' ball), and I create room and the client connects to my room and I as Master see him with my selection. ('A' ball).
And when the client is selected 'B' ball, After he connects to my room, he see himself and Master with 'B' ball.
I give screenshots:
The view of the Master:
The view of the Client:
Hope you are understanding.0 -
I guess you fetch the material as:
string materialName = PhotonNetwork.player.customProperties["BallMaterial"]
but this always return your own material. Whatever you set. Right?
So the answer is to check the ball-owners properties: view.owner.customProperties.0 -
Tobias wrote:I guess you fetch the material as:
string materialName = PhotonNetwork.player.customProperties["BallMaterial"]
but this always return your own material. Whatever you set. Right?
So the answer is to check the ball-owners properties: view.owner.customProperties.
Thank you very much!0