Single and Multiplayer game

Hi there,

I’m really new to networking and I’m starting to convert my single player game to have a co-op multi player mode. I still need the single player to work, but if my scripts are inheriting from networkbehaviours, they will only run with a server present.

Would I be likely to run into any problems if during single player, I used a network host and limited it to only support one local client, or is there a much better way to do this sort of thing?

Thanks.

No, to your question, that’s how it would work with single player. That’s how I have it now. When playing single player, you’ll just have the server and the local client, which are actually the same scenes/scripts/etc. You use the isServer, isLocalPlayer, Commands (called on client and executed on server), ClientRpcs (called on server and executed on clients), etc. to separate your code into what the server will run (isServer, Commands), what the client will run (ClientRpcs), and what the Player will run (isLocalPlayer). The Server Only checkbox on NetworkIdentity makes an object only on the server and not on clients. The Local Player Authority checkbox makes something the Player object. Checking neither allows the object to exist on the server and clients.

This is a rundown of some of the information sources available: http://wiki.unity3d.com/index.php/UNET