x


Multiplayer Game Question

Hey guys i was just wondering how to go about scripting a multiplayer game. Specifically do i need to create a multiplayer script and single player script for each character? or is it ok to make a multiplayer script that uses RPC and just call them locally on that gameobject for single player.

Also is it bad to have networkview on a Gameobject that is in single player or should there be a seperate prefab specifically for multiplayer?

Thanks for your time and any advice will be greatly appreciated!

more ▼

asked Feb 10 '11 at 06:52 PM

unitydev0008 gravatar image

unitydev0008
162 14 14 22

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You just need to add a bit of condition checking into your scripts, you don't really need to make 2 versions.

What I did is you add some variables to keep track of who the owner of the object is and use that information to determine who should be able to control the object in the game.

so...

You will set owner when instantiating the object to the Network.player that made it. var owner : NetworkPlayer;

owner = Network.player;

owner is instantiating the objects or whoever should actually control the objects if the server is authoritative.

if(Network.player == owner ) //Allow this player to control this object else //Dont do anything and just wait for the real owner to update the object

This way with a little set up in the beginning you can determine which player should be able to control the object and you dont need multiple versions of scripts to do it.

Also you can check

if(Network.isServer)

and

if(Network.isClient)

to determine if the actions are something only the server should do, or if its something that a client can do.

more ▼

answered Apr 29 '11 at 03:40 PM

AKAssassin gravatar image

AKAssassin
303 1 2 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x683
x237
x116

asked: Feb 10 '11 at 06:52 PM

Seen: 963 times

Last Updated: Feb 10 '11 at 06:52 PM