Search Unity

Resolved How to Make a Simple Local (LAN) Multiplayer?

Discussion in 'Multiplayer' started by 3, Dec 15, 2012.

Thread Status:
Not open for further replies.
  1. 3

    3

    Joined:
    Sep 16, 2012
    Posts:
    387
    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.

    Thanks,
     
    Last edited: Dec 15, 2012
  2. 3

    3

    Joined:
    Sep 16, 2012
    Posts:
    387
    Anyone? Sorry I'm struggling with the topic and can't figure it out.

    Again Sorry, but Bump
     
  3. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
  4. 3

    3

    Joined:
    Sep 16, 2012
    Posts:
    387
    Thanks, I'm going to allocate some time to watch the whole video.
     
    Zuntatos likes this.
  5. CazicThule

    CazicThule

    Joined:
    Nov 29, 2012
    Posts:
    95
    Or use NAT punchthrough?
     
  6. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    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.
     
  7. sebagius7110

    sebagius7110

    Joined:
    Dec 23, 2014
    Posts:
    5
  8. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    You replied to a 2 year old post but what's the problem you're having?
     
  9. Thelegendofbrio

    Thelegendofbrio

    Joined:
    Jul 22, 2018
    Posts:
    9
    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:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. public class PlayerScript : MonoBehaviour {
    4.     public Button Single_Player;
    5.     public Button Multi_Player;
    6.     // Use this for initialization
    7.     void Start () {
    8.         Single_Player.onClick.AddListener (delegate {SetPlayer("Singleplayer");} );
    9.         Multi_Player.onClick.AddListener (delegate    {SetPlayer ("Multiplayer");} );
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.        
    15.     }
    16.     void SetPlayer(string Where){
    17.         if (Where = "Singleplayer") {
    18.             transform.position = new Vector3 (0f, 0f, 0f);
    19.             Destroy (Single_Player);
    20.             Destroy (Multi_Player);
    21.         }
    22.         if (Where == "Multiplayer") {
    23.             //I have no idea what to do here
    24.         }
    25.     }
    26. }
     
  10. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    @Thelegendofbrio - I've just been reading through the documentation so hopefully these will help you out.

    When you're clicking the multiplayer button, you'll want to load a scene which has your NetworkManager script on a gameObject:
    https://docs.unity3d.com/Manual/class-NetworkManagerUNet.html

    To allow network discovery (LAN) you'll need to use the following:
    https://docs.unity3d.com/Manual/UNetDiscovery.html

    The example in this document shows how you can host a server on your local machine or join a server:
    https://docs.unity3d.com/Manual/UNetClientServer.html

    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.
     
    Sami_AlEsh likes this.
  11. gyfdhsij12dhu9

    gyfdhsij12dhu9

    Joined:
    Oct 23, 2020
    Posts:
    3
    2012 - 2014 - 2018 - 2021
     
  12. gyfdhsij12dhu9

    gyfdhsij12dhu9

    Joined:
    Oct 23, 2020
    Posts:
    3
    someone make it 2012 - 2014 - 2018 - 2021 - 2022 or newer
     
  13. Carybou

    Carybou

    Joined:
    Jan 24, 2022
    Posts:
    1
    2022 reporting for duty.
     
    kennahenkel likes this.
  14. MadeByBarni

    MadeByBarni

    Joined:
    Dec 10, 2022
    Posts:
    1
    Almost 2023
     
    Vincent454 likes this.
  15. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Someone please lock this thread!
     
  16. unity_1362B5C3109F097B46A6

    unity_1362B5C3109F097B46A6

    Joined:
    Oct 11, 2021
    Posts:
    1
    2023 is here.
     
    DiamondEater likes this.
  17. devzoi

    devzoi

    Joined:
    Nov 1, 2020
    Posts:
    1
    continuing 2023
     
Thread Status:
Not open for further replies.