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

  Рет қаралды 43,244

Dapper Dino

Dapper Dino

Күн бұрын

Пікірлер: 81
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
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
@pan4317
@pan4317 3 жыл бұрын
Dude nice finally a more in depth and updated multiplayer tutorial! Nice!
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Glad you liked it!
@marcelopadovan9321
@marcelopadovan9321 2 жыл бұрын
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 Жыл бұрын
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.
@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.
@Benjackalope
@Benjackalope 3 жыл бұрын
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 жыл бұрын
try changing the tick rate i think in the NetworkManager from the inspector to like 60
@AlphaLul
@AlphaLul 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@DapperDinoCodingTutorials Awesome!
@Case-A-Lace
@Case-A-Lace 3 жыл бұрын
I can't wait to try and implement this!!! thanks for more tutorials!
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Have fun!
@generaljk77
@generaljk77 3 жыл бұрын
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 Жыл бұрын
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.
@arisaek7764
@arisaek7764 3 жыл бұрын
underrated channel...
@Wavydotwtf
@Wavydotwtf 2 жыл бұрын
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.
@cauejanzinic.6263
@cauejanzinic.6263 2 жыл бұрын
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?
@kavindugayanath4629
@kavindugayanath4629 2 жыл бұрын
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
@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!!
@harry2803
@harry2803 3 жыл бұрын
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.
@rafasplaydzfolowers6145
@rafasplaydzfolowers6145 Жыл бұрын
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
@erwin7732
@erwin7732 Жыл бұрын
Same
@SantaGamerYoutube
@SantaGamerYoutube Жыл бұрын
it has been renamed to requireAuthority
@skanda2186
@skanda2186 3 жыл бұрын
Thank you for this content. Wouldn't be safe to include "Mirror" in the video title ?
@dmo224
@dmo224 3 жыл бұрын
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 жыл бұрын
Whoever has this problem: "ignoreAuthority=true" changed to "requiresAuthority=false"
@daskebabibnahmedal-kohol8119
@daskebabibnahmedal-kohol8119 2 жыл бұрын
I think you may need to remake this. Many of the functions have been changed
@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!
@sergeymalyshev2704
@sergeymalyshev2704 3 жыл бұрын
You're the best, thank you!
@DerperDoing
@DerperDoing 3 жыл бұрын
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 жыл бұрын
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?
@TheUncutAngel
@TheUncutAngel 3 жыл бұрын
//dino casually writes modulo % and blows my fucking mind
@erwin7732
@erwin7732 Жыл бұрын
How Did you Add Character Selection in Create in top of a folder? i can't Find than
@李志-d2p
@李志-d2p Жыл бұрын
Spawned object not found when handling Command message [netId=0]
@ashdev
@ashdev 3 жыл бұрын
Can you also discuss the pricing in a video. Please its complicated.
@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?
@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
@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
@rabsfeir
@rabsfeir 3 жыл бұрын
does anyone have a different camera inspector menu from above but me??? some renderer addition i should have maybe?
@blaiseflorendo3967
@blaiseflorendo3967 3 жыл бұрын
yes, me also my inspector is different from his
@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?
@yeetswa
@yeetswa 2 жыл бұрын
Would i be able to using visual scripting , e.g game creator asset or playmaker asset with Playfab?
@muratcan118
@muratcan118 2 жыл бұрын
Video for mobil joystick please
@starlord6743
@starlord6743 3 жыл бұрын
love it
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Great to hear!
@pixlabots1233
@pixlabots1233 2 жыл бұрын
doesnt work with isLocalPlayer. How to resolve?
@TheUncutAngel
@TheUncutAngel 3 жыл бұрын
What's your opinion on the benefits of mirror vs mlapi?
@XboxPlayerPL
@XboxPlayerPL 2 жыл бұрын
Mirror is production ready
@tmgamer7661
@tmgamer7661 3 жыл бұрын
TY❤️
@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...
@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.
@SahilSingh-hc4fk
@SahilSingh-hc4fk Жыл бұрын
use "requiresAuthority =false" instead of "ignoreAuthority=true"
@Zeak6464
@Zeak6464 2 жыл бұрын
how to change spawn location ?
@dascience1147
@dascience1147 3 жыл бұрын
where's the first video?
@astralstormgamestudios1259
@astralstormgamestudios1259 3 жыл бұрын
What network solution are you using?
@XboxPlayerPL
@XboxPlayerPL 2 жыл бұрын
Mirror Networking
@rabiehaddad1925
@rabiehaddad1925 3 жыл бұрын
How to make using photon
@kevin_raney
@kevin_raney 3 жыл бұрын
Go go multi-player power...
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Whoop!
How To Make A Multiplayer Game In Unity - Authentication
10:04
Dapper Dino
Рет қаралды 20 М.
How To Make A Multiplayer Game In Unity 2021.1 - Syncing Variables
13:17
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 13 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,7 МЛН
How To Make A Unity Multiplayer Character Selection Menu - Part 1
32:22
THIRD PERSON MOVEMENT in Unity
21:05
Brackeys
Рет қаралды 1,5 МЛН
How To Make A Multiplayer Game In Unity - Matchmaking
17:38
Dapper Dino
Рет қаралды 29 М.
Multiplayer character selection - UNITY & PHOTON 2 Tutorial!
26:06
Blackthornprod
Рет қаралды 66 М.
Unity Tutorial - Simple Character Selection System
5:30
RumpledCode
Рет қаралды 87 М.
How to Build a Multiplayer Game with Unity + Mirror
26:30
Shrine
Рет қаралды 178 М.
9 EASY Steps to create a multiplayer game with Unity & Photon - Tutorial
15:51