- Home /
Question by
SomeGuy22 · Sep 09, 2012 at 07:05 PM ·
transformmultiplayerplayeractive
Multiplayer Changing Who "Owns" a Script?
I have this code that runs an npc over multiplayer:
function OnSerializeNetworkView (stream : BitStream, msg : NetworkMessageInfo)
{
var newPos = pos;
var newRot = rot;
var active = isactive;
stream.Serialize(active); // always send / receive the active flag
if (active)
{
stream.Serialize(pos); // only send / receive pos / rot when active
stream.Serialize(rot);
}
if (stream.isWriting) {
//moar codez
} else {
if (active)
{
transform.position = pos;
transform.rotation = rot;
}
}
}
"active" means that the npc script is being moved by a player.
And that works fine if player 1 holds activeness, but now I want to make it so that the nearest player holds activeness, and now I'm getting syncing issues.
The problem is not how to get the nearest player but how to make it so that the nearest player sends the data and all others receive it.
Why does changing the active variable make this code not work?
Comment