- Home /
Networking sync enabled state?
Hi,
I have figured out how to sync position and rotation, but I was wondering how to synchronize the enabled/disbled state of an object?
Thanks in advance,
Andreas.
Answer by softrare · Jan 06, 2014 at 04:42 PM
You can do it like that (untested but should work):
public bool objEnabled;
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
//print ("writing");
stream.Serialize(ref objEnabled);
}
else
{
//print ("reading");
bool tmpEnabled = false;
stream.Serialize(ref tmpEnabled );
objEnabled = tmpEnabled;
}
}
Put that in a script and put it on the same gameobject as your NetworkView component.
likewise if with enabled/disabled you mean if the active state of a gameObject you should be able to find the right calls in the Unity api.
Hi, thanks for your answer :) What I meant was the active state of a gameObject. Do you know where can I find docs for that?
What I'm trying to achieve: When the player you control die, an explosion appears. On all the other players, that explosion should be enabled (as it's enabled in your own Networking View), so they can see it also.
In that case look at RPCs: http://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html
Okay, thanks :)
How would that work, when I only need to send the active state to the other players and not the position e.g.?
Your answer
Follow this Question
Related Questions
Networking Physics / Object Ownership / State Sync 1 Answer
Networking Sync SetActive Not Working 0 Answers
How to sync network 0 Answers
How fast do Syncvars synchronize? 1 Answer
UNET Server not setting [SyncVar] 0 Answers