Hey Guys, I’ve been scratching my head so hard I lost hair. If someone could help me it would be great. I’ve set up a network correctly with server and client, I’ve got my main camera detached from the prefab and when I instantiate I move the Main Camera to one of the Clones because my camera needs to follow correctly a children in my prefab. Anyway everything went well until now, I can control the server and the client separately so everything is fine except two nasty things. I have particles in the prefab and in my player script I disable them pointing to the player tag at runtime (if anyone asks I’m attempting to do a little test at spacesim) the only problem is that when I play, I always see other clones as having the particles as if I never disabled them. What I feel is weird is that if I see in each client or server window, the particles are disabled but it seems like if other players weren’t aware of the particle disabling for the others.
If anyone can help me I appreciate, it’s my first time around here and I don’t really like asking questions but this time around I really can’t do anything, it’s been three days and I’m quite tired by now. Thank you very much.
I guess you are disabling particles using some line like particleEmitter.enabled = false, and you are doing it only on local.
You only affect your own copy of the network instantiated prefab, plus you may not be the owner, plus this state can’t be state synchronized by the network view (unless a script is observed, with OnSerializeNetwork, or by using RPC functions).
You best bet is to make a RPC function.
@RPC
function SetParticleEmitterState (state : bool) {
particleEmitter.enabled = state ;
}
When you want to enable or disable particles for a network instantiated prefab present on all clients and server, try using this.
networkView.RPC ("SetParticleEmitterState", RPCMode.All, true);
networkView.RPC ("SetParticleEmitterState", RPCMode.All, false);
(I hope I am not saying crap…)
Merci sa a marché. That seems to have done the trick but it just works on the first instance I make. I must have a really wrong code.
Maybe it is because I do GameObject.FindWithTag(), I imagine this doesn’t work really well with instantiated players. I’ve seen and use part of the code of multiplayer Tutorial by M2H but it didn’t work either. Anyway that did the trick for the first instance so I’ve got to search why it doesn’t do it for all the instances.
GameObject.FindWithTag
GameObject.FindObjectsWithTag
The first returns only one gameObject. The second returns the entire list of all gameObjects with the right tag. Use the second instead of the first.
The best solution is onNetworkView.isMine