- Home /
One user controls all of them on network
When one person moves it animates all people on the server.
This is making everyone walk!
var view : NetworkView;
@RPC
function walk() { //this function is called when a user presses w
//print(networkView.viewID);
view = NetworkView.Find(networkView.viewID);
view.gameObject.transform.networkView.RPC("isWalking", RPCMode.All);
}
isWalking just sets a boolean isWalking to true for a specific player object. This is doing it to all of them and I am not sure why!
Also I am getting this usse, perhaps it is related?
NullReferenceException: Object reference not set to an instance of an object networkmanager.spawnPlayer () (at Assets/scripts/networkmanager.js:60)
function spawnPlayer() { //occurs onConnection and onInitialization
var viewID = Network.AllocateViewID();
var clone : Transform;
clone = Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0) as Transform;
var nView: NetworkView;
nView = clone.GetComponent(NetworkView); //THIS IS THE LINE WITH THE ERROR
nView.viewID = viewID;
}
Ins$$anonymous$$d of sending RPC's you may just use networkView controllers and check if the networkView.is$$anonymous$$ine. That should keep only the person sending the input able to move only his player, and it is what networkViews were created for...
What are networkView controllers?
and where should I check is$$anonymous$$ine.
I am sorry, one user controls only himself. The issue is that a boolean is changed that belongs to all of them.
thank you so much :D :D :D :D :D :D :D :D I will read and digest all of this = ) ! ! !
Awesome if it answered your question I will post as answer and you can mark it. :)
Answer by fifthknotch · Mar 09, 2014 at 07:46 AM
Check out these docs real quick they outline what networkView controllers are (I say controllers but really they are just components. They are located under "miscellaneous => networkView"), where to find them, how to use them, etc.
http://docs.unity3d.com/Documentation/Components/class-NetworkView.html
You check for networkView.isMine as an if statement surrounding the movement portion of your script. If you do this, you would no longer need RPC's to send player movement because networkView's sync the object transforms across all connected machines
ty again = ) I am stil lreading through it but I am not totally sure. If you don't $$anonymous$$d can you explain 'transforms'?
Sure! Transforms hold three sets of data: position, rotation, and scale.
$$anonymous$$ so I did what you said! The only issue is that it doesn't show when other players move. So on machine A when user A moves, only user A is shown the animation. When user B looks at user A the animation does not display.
if (is$$anonymous$$oving && networkView.is$$anonymous$$ine){
child.animation.Play("Walk");
}
else {
child.animation.Play("Idle");
}
function OnSerializeNetworkView(stream : BitStream, info : Network$$anonymous$$essageInfo) {
var _is$$anonymous$$oving : boolean = is$$anonymous$$oving;
stream.Serialize(_is$$anonymous$$oving);
}
Your answer
Follow this Question
Related Questions
How can I get "!networkView.isMine" to function properly? 1 Answer
Client to client Serialization 1 Answer
How do I separate network views? 0 Answers
Network: any way to check in detail the data transmission? 1 Answer
What is Send rate? 1 Answer