I’m completely new to the multiplayer aspect of Unity, and I don’t know where to start.
However as of right now, I have a Free-roam racing game, and Is there any way to simply, with no or minimal code, just have someone else join the game? There wouldn’t have to any changes to the game, it would be as if they are playing single player, but with the other car there too. Think how Rockstar makes their multiplayer, they just drop many people into a world and let them play it out. I imagine it would be simple enough.
Is there something on the asset store to do this? Or maybe some code somewhere so I can edit it but have a foundation for what to do?
The only networking example project I found, which was on the Unity website, is outdated and targeted for Iphones. When I copied it to the letter, It didn’t work.
Well using built in networking or UnityPark suite of www.muchdifferent you just need to change your instantiate and Destroy calls to Network.Instantiate and Network.Destroy
and add a smoothRigidbody to your racing stuff. If you have other world events then you should notify others using RPCs when they happen, otherwise nothing.
UnityPark suite is recommended and has a good SmoothRigidbody script for syncing rigidbodies. Unity’s own networking example has a script for that as well.
I just want a simple LAN join function, I want to create a menu with a “Single player” and a “Multiplayer” option.The Buttons are ready and all, but I don’t know how to allow players to connect over LAN, here is how far I got:
using UnityEngine;
using UnityEngine.UI;
public class PlayerScript : MonoBehaviour {
public Button Single_Player;
public Button Multi_Player;
// Use this for initialization
void Start () {
Single_Player.onClick.AddListener (delegate {SetPlayer("Singleplayer");} );
Multi_Player.onClick.AddListener (delegate {SetPlayer ("Multiplayer");} );
}
// Update is called once per frame
void Update () {
}
void SetPlayer(string Where){
if (Where = "Singleplayer") {
transform.position = new Vector3 (0f, 0f, 0f);
Destroy (Single_Player);
Destroy (Multi_Player);
}
if (Where == "Multiplayer") {
//I have no idea what to do here
}
}
}
For LAN i assume you’re using a listen server so that should work for you.
I don’t know how much multiplayer code you’ve actually implemented, multiplayer is not something you just switch on, you need to define the networked objects and variables that you want to synchronise and set up your spawnable objects etc before you can actually get basic multiplayer working.
I suggest reading through the documentation and/or watching some video tutorials as a starting point.
Understanding how everything works before you start trying to implement it is a lot easier than trying to add multiplayer piece by piece. There are a lot of considerations that are better to be dealt with up front.