How To Make A Multiplayer Game In Unity (Mirror) - Character Selection

Поділитися
Вставка
  • Опубліковано 5 лис 2024

КОМЕНТАРІ • 81

  • @DapperDinoCodingTutorials
    @DapperDinoCodingTutorials  3 роки тому +9

    Thanks for watching this Unity Multiplayer tutorial. For project files access, check out my GitHub here: github.com/DapperDino/Mirror-Multiplayer-Tutorials

    • @tatumleonidas1444
      @tatumleonidas1444 3 роки тому

      i guess it is kind of randomly asking but does anybody know a good site to watch newly released series online ?

    • @edenty1716
      @edenty1716 3 роки тому

      @Tatum Leonidas Flixportal :)

    • @tatumleonidas1444
      @tatumleonidas1444 3 роки тому

      @Eden Ty Thank you, I signed up and it seems to work :) Appreciate it!

    • @edenty1716
      @edenty1716 3 роки тому

      @Tatum Leonidas glad I could help xD

  • @marcelopadovan9321
    @marcelopadovan9321 2 роки тому +4

    For those who need the LocalPlayer, just replace:
    NetworkServer.Spawn(characterInstance, sender);
    for:
    NetworkServer.ReplacePlayerForConnection(sender, characterInstance);
    maybe can help, works for me.

  • @talismanskulls2857
    @talismanskulls2857 Рік тому +1

    Thanks Dapper for the tutorials. I thought I would share a quick and easy alternative to this method. And its WAY less code needed.
    1) Bring out you base prefabs used only for representation of the player to be loaded.
    2) Create two toggles, one for the ybot and xbot.
    3) Create two slots for the On Value Change and place both the male and the female bots from the scene into both slots for both toggles and use the GameObject and SetActive (bool).
    4) Under the male toggle/button set the male as active with the check and leave the other unchecked for the female. On the female toggle do the exact opposite.
    5) Start scene and test to make sure one is active when the other isn't on the appropriate button. (Note you can add an empty named Button Audio , give it an audio source, and select a button click sound, and use the same method but go down to the audio list and select the play one shot and also giving it a specific click sound. Just make sure on the empty game object audio source you uncheck the play on awake.
    Now for the script side .
    using UnityEngine;
    public class CharSelect : MonoBehaviour
    {
    [Header("Character Selection")]
    public GameObject[] _Char;
    int _CharIndex = 0;
    Header("Load Scene Button")]
    public GameObject[] _Char;
    int _CharIndex = 0;
    public void ChangeCharacter()
    {
    for (int i = 0; i < _Char.Length; i++)
    {
    _Char[i].SetActive(i == _CharIndex);
    }
    }
    public void _Male(bool qualityIndex)
    {
    _CharIndex = 0;
    ChangeCharacter();
    PlayerPrefs.SetInt("_CharIndex", _CharIndex);
    }
    public void _Female()
    {
    _CharIndex = 1;
    ChangeCharacter();
    PlayerPrefs.SetInt("_CharIndex", _CharIndex);
    }
    }
    public void _goToLoginScene()
    {
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
    6) Create the empty naming it Char Select and add the script.
    7) Drag the two actual player prefabs that have your control and movement script on them and into the CharSlect option.
    8) Drag the Char Select object into the same part you added the swap sample scene models. and under that look for the appropriate corresponding chacter , IE _Male for Male character, etc.
    9) Add the character Select scene to Build settings.
    10) Do the same with the Load/Play button by finding in the list the _goToLoginScene in that list and apply it.
    (For added measure i take audio listener off cameras and put them directly on the player characters so you wont have that issue where the camera is closer to an audio source than the avatar is and creates all sorts of funky issues.)
    11) Save things and add the CharSelect Scene to Build settings.
    12) Now create the new scene Level1 or LoadPlayer, whatever you want to name it. Add it to the build setting also. as the second in list.
    13) Create the UI as show, but also set the AspectRadio at the top next to the button for display and set the UI to Scale with Screen size. The create the UI parts like the text.
    Now create the LoadChar script.
    using UnityEngine;
    using UnityEngine.UI;
    using TMPro;
    public class LoadChar : MonoBehaviour
    {{
    [Header("Player Settings")]
    public GameObject [] player;
    public Transform playerSpawn;
    public TMP_Text label;
    [Header("Spawn CamRig")]
    public GameObject camRig;
    // Start is called before the first frame update
    void Start()
    {
    // player spawn locations
    int _CharIndex = PlayerPrefs.GetInt("_CharIndex", 0);
    GameObject prefab = player[_CharIndex];
    GameObject clone = Instantiate(prefab, playerSpawn.position, Quaternion.identity);
    clone.transform.position = playerSpawn.position;
    // character name label
    label.text = prefab.name;
    // camera spawn
    Instantiate(camRig, transform.position, transform.rotation);
    }
    }
    }
    1) The player that was selected if set up as explained with its dummy rep in the previous scene used only as an indicator of a selection, the character selected will load once you add those prefabs to this script in the next scene.
    2) it has the added option for spawning a camera prefab to loads as well that prevents extra cloning of the camera if you want the UI and LoadChar to persist between other scenes such as when triggering a scene change using a portal or door or whatever.
    3) If you simply attach a camera directly to the player or the UI it will often be replicated constantly and replicating the clones X2or more if you dont use this spawn camera method and rather quickly will start killing frame rates and lead to a major crash.
    As to how to make a camera that follows the player still find it when spawned/instantiated, you have to link the Player script and the Cam script to find one another.
    How I do that is I create an empty and name it camTarg for the camera target and align it with the eye level area of the player character. I add to it a tag called CamTarg.
    I then do this (Create parent Object to hold Camera Script, setting all its positions to 0. I create a child object called pivot and also set it to zero. Then I place the MainCamera as a child of the pivot (you can also call the pivot something like tilt)).
    With the camera, however, I raise it about 1.5 on the Y axis and put it at a -3 on the z axis. I give the parent the name CamRig abd also create a Tag and apply that to the parent which is where you will also place your camera scripting.
    With all that being done and it having a basic follow player script already added, in the camera script just add this line code:
    PlayerController player;
    public Transform tilt;
    Camera mainCam;
    // Update is called once per frame
    public void Init()
    {
    player = FindObjectOfType();
    mainCam = Camera.main;
    transform.position = player.transform.position + Vector3.up * camHeight;
    transform.rotation = player.transform.rotation;
    }
    And whatever other parts are needed for your particular camera system.
    In your Player Script just add this:
    public void Start()
    {
    CameraControl cameraControl = FindObjectOfType();
    cameraControl.Init();
    }
    Once you are done with all that, add the CamRig Prefab you made into the LoadChar script. I also create a prefab of the cCamTarg that is inside the player so i can drag it into the Prefab CamRig so it recognizes it, separate from the player characters it is also saved inside the prefabs of. if you dont do it that way, when ever they player and cam load, you will be thrown an error notice of missing something.
    Now i just have to figure out how to tie character select to a register/login so the right character is part of the authentication process. That's the part I am still struggling with. LOL.

    • @sasuke1234ization
      @sasuke1234ization Рік тому

      hi bro do you have discord so i can contact you about this? Thanks.

    • @talismanskulls2857
      @talismanskulls2857 Рік тому

      @@sasuke1234ization Not on it very much but yes. Be aware I am not very good at coding a lot of things. I just figured out how to fix some issues like this. Look for TalismanSkulls using the same avatar as here.

    • @sasuke1234ization
      @sasuke1234ization Рік тому

      @@talismanskulls2857 Request sent.

  • @pan4317
    @pan4317 3 роки тому +5

    Dude nice finally a more in depth and updated multiplayer tutorial! Nice!

  • @AlphaLul
    @AlphaLul 3 роки тому +12

    I think a PlayFab tutorial about an Among Us style lobby system would be cool, with a list of public games to join and the ability to join a private game with a random code. Also, it would be nice to have the ability to join a random lobby, because with the current Among Us system, it can sometimes be difficult to join a lobby.

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  3 роки тому +7

      The more advanced PlayFab tutorials like matchmaking (and lobbies/list servers) will take a bit longer to make but I will be covering lobbies/list server after we've looked into matchmaking :)

    • @AlphaLul
      @AlphaLul 3 роки тому +1

      @@DapperDinoCodingTutorials Awesome!

  • @Benjackalope
    @Benjackalope 3 роки тому +2

    Thank you soo much! I'm still stuck on making movement sync properly from one of your earlier tutorials, but I'm excited to implement this!

    • @hazemackle2650
      @hazemackle2650 3 роки тому +1

      try changing the tick rate i think in the NetworkManager from the inspector to like 60

  • @niklaswild
    @niklaswild 2 роки тому

    You have helped me so much. I didn't actually watch your video though, just used your idea of multiple prefabs. I always tried to change the material from the player before. But that has only ended in chaos.

  • @Case-A-Lace
    @Case-A-Lace 3 роки тому +1

    I can't wait to try and implement this!!! thanks for more tutorials!

  • @arisaek7764
    @arisaek7764 3 роки тому

    underrated channel...

  • @generaljk77
    @generaljk77 3 роки тому +5

    Awesome tutorial! I have everything working as the tutorial shows, but what would you recommend as being the best way to take the player's character selected and move them into a new scene with the chosen character?

    • @xxasafxx1
      @xxasafxx1 2 роки тому

      Do you have the answer?

    • @dudley1562
      @dudley1562 Рік тому

      Make a function like...
      Public Void StartGame(string sceneName)
      {
      ServerChangeScene(sceneName);
      }
      ist part of Mirror.NetworkManager

  • @shadowzack
    @shadowzack 5 місяців тому

    This may be a bit of a long shot, but do you know of any tutorials/examples for trying to change a players character/prefab while the game is already running.

  • @Wavydotwtf
    @Wavydotwtf 2 роки тому +1

    getting this error - NetworkPlayer(Clone) has already spawned. Don't call Instantiate for NetworkIdentities that were in the scene since the beginning (aka scene objects). Otherwise the client won't know which object to use for a SpawnSceneObject message.

  • @TheUncutAngel
    @TheUncutAngel 3 роки тому

    //dino casually writes modulo % and blows my fucking mind

  • @cauejanzinic.6263
    @cauejanzinic.6263 2 роки тому +1

    Right after I associated the Character Selection script in the right and left button, every time I click on the buttons, I get this error "ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index", does anyone know how I can fix it?

  • @starlord6743
    @starlord6743 3 роки тому +2

    love it

  • @sergeymalyshev2704
    @sergeymalyshev2704 3 роки тому

    You're the best, thank you!

  • @kavindugayanath4629
    @kavindugayanath4629 2 роки тому +1

    Player spwoner not working and (ignoreAuthority = true) show error. Trying to send command for object without authority. System.Void DapperDino.Mirror.Tutorials.CharacterSelection.CharacterSelect::CmdSelect(System.Int32,Mirror.NetworkConnectionToClient)

    • @nrmines1754
      @nrmines1754 2 роки тому

      try requiresAuthority=false

  • @daskebabibnahmedal-kohol8119
    @daskebabibnahmedal-kohol8119 2 роки тому +1

    I think you may need to remake this. Many of the functions have been changed

  • @harry2803
    @harry2803 3 роки тому +1

    may I make a suggestion for your next video in this playlist.
    could you go back to your lobby tutorials and add a system where after each game finishes you go back to the lobby and maybe you could add a scoring system which is what i am doing for the game i am currently creating. Im not too sure on how I myself would get this to work beacuse when you start a game you leave the lobby scene to the game scene. so there would need to be some way you could bring your name and score to the game scene then after winning or finishing a game (or in this case just automatically ending the game probably is easiest) you would have to bring your name and score back and then have to set up the whole lobby which could be complicated which is why I am asking you.

    • @brodakarat6340
      @brodakarat6340 2 роки тому

      The next thing on my too list is going back to my lobby and revamping it. I'm gonna add a host only panel for match settings like map selection, max squads, show bullet trails etc. I'm also going to add a pause menu ingame and work on the post death experience (spectating and return to lobby) so I might be able to help once I do that.
      My first solution I would want to try is to just do a ServerChangeScene back to lobby scene, as my my players are DontDestroyOnLoad I only need to refactor my lobby to accept already existing players and it should work. For your scoring you would just have a DontDestroyOnLoad object which holds your game data like scores (this is how I will tackle my match settings thing). Making it all SyncVar's you can set score on the server and they are automatically synced to clients eg to display it on screen in the lobby.

  • @ashdev
    @ashdev 3 роки тому

    Can you also discuss the pricing in a video. Please its complicated.

  • @rafasplaydzfolowers6145
    @rafasplaydzfolowers6145 Рік тому +1

    hey bro i have a problem with the CharacterSelect script :CharacterSelect.cs(54,18): error CS0246: The type or namespace name 'ignoreAuthority' could not be found (are you missing a using directive or an assembly reference? I would be very grateful if you help me

  • @muratcan118
    @muratcan118 2 роки тому +1

    Video for mobil joystick please

  • @gabrielmarques8657
    @gabrielmarques8657 3 роки тому

    Is it possible to use mirror networking as a room based system like Photon? For mobas/brawlers for example? Found a couple of things about lobby and server list, but I'm wondering if one server can host multiple game instances concurrently... Thanks for the videos, great content!

  • @erwin7732
    @erwin7732 Рік тому

    How Did you Add Character Selection in Create in top of a folder? i can't Find than

  • @skanda2186
    @skanda2186 3 роки тому +4

    Thank you for this content.
    Wouldn't be safe to include "Mirror" in the video title ?

  • @fernandomilans8444
    @fernandomilans8444 3 роки тому

    Hello, the videos you make are very good and very well explained.
    Can you tell me if the management with the databases is very complicated, for example, the login system?
    And also, in the game get the data of all the players, for example, if you type "Shift 'it shows a table with the number of deaths of the players (if it were a shooter).
    I think for server and database hosting, from what I read, unity has a service for this, right?
    Thank you very much!!

  • @李志-d2p
    @李志-d2p Рік тому

    Spawned object not found when handling Command message [netId=0]

  • @dmo224
    @dmo224 3 роки тому +1

    For some reason I can not tell the Command to ignore authority. [Command(ignoreAuthority=true)] does not work for me, the IDE says that it doesn't recognize the "type or namespace". Maybe I'm using the wrong version of Mirror?

    • @dmo224
      @dmo224 3 роки тому

      Wrong version, sort of... This error was brought to me by VIVOX and their implementation of Mirror.

    • @ЧарлиНиен
      @ЧарлиНиен 3 роки тому +8

      Whoever has this problem: "ignoreAuthority=true" changed to "requiresAuthority=false"

  • @tmgamer7661
    @tmgamer7661 3 роки тому

    TY❤️

  • @rabsfeir
    @rabsfeir 3 роки тому +2

    does anyone have a different camera inspector menu from above but me??? some renderer addition i should have maybe?

  • @DerperDoing
    @DerperDoing 3 роки тому +1

    What if I just want to randomly assign color from a list to a Player Prefab(cube) of Network Manager every time a player joins rather than creating multiple cube prefabs with different colors?
    The way I'm doing, the color changes only in the host whereas it is not synced when the next player joins the lobby. Whatever color the new player has, every other player has that same color.

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  3 роки тому +1

      You can make it a [SyncVar] and then use the hook call-back to set the colour on clients. Let me know if you need any more help :)

    • @DerperDoing
      @DerperDoing 3 роки тому

      @@DapperDinoCodingTutorials I initially thought of doing it that way. But what I am really using is a list of different materials which I want to sync.
      Is there a way to do so?

  • @yeetswa
    @yeetswa 2 роки тому

    Would i be able to using visual scripting , e.g game creator asset or playmaker asset with Playfab?

  • @liliansananikone3588
    @liliansananikone3588 2 роки тому

    Hi !
    I'm currently using Mirror Networking to make a multiplayer game. I have a scene when players are all connected, they can choose their characters and set the ready. If all players are ready, I change current scene to arena scene using MyNetworkManager.ServerChangeScene(arenaSceneName). This method sets all player clients as not ready. But After the scene was loaded, my player client is no longer connected to my host and I don't know why.
    Can you help me please ?
    Thanks a lot for answers.

  • @elenavillepreux1842
    @elenavillepreux1842 2 роки тому

    Hi, thanks for your tutorial, very useful ! in my unity project i have a network manager with spawn points and i want to spawn the character I choose at the position of theses spawn points, i put the network player attached to the network manager but it doesn’t seem to work. The player spawns at the position of the prefab and it is impossible to move, the scene camera is still active. Do you know how to solve this problem?

  • @daskebabibnahmedal-kohol8119
    @daskebabibnahmedal-kohol8119 2 роки тому

    By default, the movement with wasd is based on the direction of the map. using third person with camera at the back, any way to disable that?

  • @SahilSingh-hc4fk
    @SahilSingh-hc4fk Рік тому +1

    use "requiresAuthority =false" instead of "ignoreAuthority=true"

  • @ghostaspirine9784
    @ghostaspirine9784 3 роки тому

    I need help, when i spawn my character, it isnt LocalPlayer and its destroying the controller. Do you have an idea please how can i make it become localplayer please

  • @intercooler729
    @intercooler729 3 роки тому

    i need help My camera mouselook script wont work i added the networking and every thing
    its the same as brackeys Mouselook in his first person movement video

  • @TheUncutAngel
    @TheUncutAngel 3 роки тому

    What's your opinion on the benefits of mirror vs mlapi?

  • @pixlabots1233
    @pixlabots1233 2 роки тому

    doesnt work with isLocalPlayer. How to resolve?

  • @you10496
    @you10496 2 роки тому

    Okay, so is there any way to make the spawn the player as local player instead? Cause in this method we are not spawnih them as local player so we can't use local player functions :thinking:

    • @Nirvan794
      @Nirvan794 10 місяців тому

      Did you find a way to make it work?

  • @maniksharma9736
    @maniksharma9736 3 роки тому

    What about multiplayer sounds...

  • @Zeak6464
    @Zeak6464 2 роки тому

    how to change spawn location ?

  • @Vinet164
    @Vinet164 3 роки тому

    How do you make a different spawn point for each character?

    • @Sulihin
      @Sulihin 3 роки тому

      Check out the earlier tutorial in the series "Spawning Players In" tldw; You can make empties with the NetworkSpawnPosition component.

  • @astralstormgamestudios1259
    @astralstormgamestudios1259 3 роки тому

    What network solution are you using?

  • @dascience1147
    @dascience1147 3 роки тому

    where's the first video?

  • @rabiehaddad1925
    @rabiehaddad1925 3 роки тому

    How to make using photon

  • @kevin_raney
    @kevin_raney 3 роки тому +2

    Go go multi-player power...