Unity Character Customization - Steam Multiplayer Game in Unity
HTML-код
- Опубликовано: 22 май 2024
- Check out the Unity SPRING SALE!!!
assetstore.unity.com/?on_sale...
assetstore.unity.com/?flashde...
Source Code: / 65189989
In this video I will be showing you how to implement character customization . I will go over how to get the initial UI and system working. And also how to load this into the game and get it synced across the network.
----Tutorial Links----
Previous Video: • How To Make a Steamwor...
Steam Docs: partner.steamgames.com/doc/home
----My Personal Links----
Discord: / discord
Instagram: / gabzxd
Twitch: / officialzyger
Twitter: / zygerdesigns
-----My Personal Links-----
Discord: / discord
Instagram: / gabzxd
Twitch: / officialzyger
Twitter: / zygerdesigns
➤WISHLIST MY GAME:
store.steampowered.com/app/16...
----Time Stamps-----
0:00 - Intro
0:52 - UI and Unity Setup
1:33 - Customizations Setup
4:23 - Unity Changes
5:37 - Syncing Over the Network
8:32 - Final Unity Changes
8:54 - Testing - Развлечения
just found your channel 30 minutes ago and it has this steam multiplayer series AND a save and load level system? thanks for these tutorials, ill really need them for my game!
Thank you for making these tutorials Zyger it's helped me a ton!
What a helpful tutorial enjoyed it ❤️
Another Banger and the exact thing I needed❤
Another fantastic tutorial. Thanks for the upload!
thank you
brb, learning how to make a triple A game from these tutorials!
😂
Thank you, you’re amazing!
Thanks, great tutorial!
Thanks !
Hey, nice video, I dont know much about unity or c#, but I think a nice feature to add if you press on the next color arrow and its the end of the color ( a.length ) it will go back to the first color so it will still switch colors and wont stuck. =)
Yeah that's definitely what I would do if I continued the project. For the video I didnt bother adding it but definitely a great idea.
Seems like a fairly simple fix by just checking which button you hit and if the current index is at the end, set it to the start value
You can edit your script to this for that functionality :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Steamworks;
using Mirror;
public class CharacterCosmeticsController : MonoBehaviour
{
public int currentColorIndex = 0;
public Material[] playerColors;
public Image currentColorImage;
public Text currentColorText;
private static string CURRENT_COLOR_INDEX = "currentColorIndex";
private void Start()
{
currentColorIndex = PlayerPrefs.GetInt(CURRENT_COLOR_INDEX, 0);
UpdateNewColorUI();
}
public void NextColor()
{
if (currentColorIndex < playerColors.Length - 1)
{
currentColorIndex++;
PlayerPrefs.SetInt(CURRENT_COLOR_INDEX, currentColorIndex);
UpdateNewColorUI();
}
else if (currentColorIndex == playerColors.Length - 1)
{
currentColorIndex = 0;
PlayerPrefs.SetInt(CURRENT_COLOR_INDEX, currentColorIndex);
UpdateNewColorUI();
}
}
public void PreviousColor()
{
if (currentColorIndex > 0)
{
currentColorIndex--;
PlayerPrefs.SetInt(CURRENT_COLOR_INDEX, currentColorIndex);
UpdateNewColorUI();
}
else if (currentColorIndex == 0)
{
currentColorIndex = playerColors.Length - 1;
PlayerPrefs.SetInt(CURRENT_COLOR_INDEX, currentColorIndex);
UpdateNewColorUI();
}
}
private void UpdateNewColorUI()
{
currentColorImage.color = playerColors[currentColorIndex].color;
currentColorText.text = playerColors[currentColorIndex].name;
}
}
Awesome tutorial serie, really helpful and straight forward. It might be awesome if you could create a tutorial for making a two teams game. I can't figure out how to modify your script to make the networkmanager split players into different teams. I tried by myself and even asked to ChatGPT but it's the same; a bunch of errors or the script isn't working as intended. When I managed to make it work, the original GamePlayer is still spawning and isn't controlled by anyone in the middle of the scene. Thanks a lot for this tutorials btw taught me a lot about NetworkBehaviour and how to manage a multiplayer lobby!
If you are having trouble with the colours not updating, it's because the CmdUpdatePlayerColor function is never called. To resolve this, you need to reference the LobbyController Instance (specific to the player), call the cmd function and input the index number from the lobby via the use of:
LobbyController.Instance.LocalplayerController.CmdSendPlayerColor(index);
This is my version of the CharacterCosmetics.cs class, I've used TMPro instead of the UI component as the old text features are now not recommended in later Unity versions. I also removed the 'PlayerPrefs.GetInt("currentColourIndex", 0);' in the start function, as it would cache previous choices which I didn't want to implement in my interpretation. Wrapping was also added so when you reach the last colour, it loops back to the first!
----------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Steamworks;
using Mirror;
public class CharacterCosmetics : MonoBehaviour
{
public int currentColorIndex = 0;
public Material[] playerColors;
public Image currentColorImage;
public TextMeshProUGUI currentColorText;
private void Start()
{
// Generate new Steamworks variable, and set to 0 if not already created
// currentColourIndex = PlayerPrefs.GetInt("currentColourIndex", 0);
SetColor(currentColorIndex);
}
private void SetColor(int index)
{
PlayerPrefs.SetInt("currentColourIndex", currentColorIndex);
currentColorImage.color = playerColors[currentColorIndex].color;
currentColorText.text = playerColors[currentColorIndex].name;
LobbyController.Instance.LocalplayerController.CmdSendPlayerColor(index);
}
public void NextColor()
{
if (currentColorIndex < playerColors.Length - 1) // Increment
currentColorIndex++;
else if (currentColorIndex == playerColors.Length - 1) // Wrap
currentColorIndex = 0;
SetColor(currentColorIndex);
}
public void PreviousColor()
{
if (currentColorIndex > 0) // Decrement
currentColorIndex--;
else if (currentColorIndex == 0) // Wrap
currentColorIndex = playerColors.Length - 1;
SetColor(currentColorIndex);
}
}
HI. I too do not get the chosen colors applied. I replaced your code into CharacterCosmetics.cs but then got this below error. Are there some other code changes to other scripts? : error CS1061: 'PlayerObjectController' does not contain a definition for 'CmdSendPlayerColor' and no accessible extension method 'CmdSendPlayerColor' accepting a first argument of type 'PlayerObjectController' could be found (are you missing a using directive or an assembly reference?). Thanks!
@@kcdahnert It's because you cmd is called 'CmdUpdatePlayerColor', not 'CmdSendPlayerColor' (if you strictly followed Zyger's tutorial :) )
It works but I keep getting this error: Command System.Void PlayerObjectController::CmdUpdatePlayerColor(System.Int32) called on PlayerObject without an active client.
Hey Zyger, I'm a 3D modeller who's trying to make a game on his own. I can't code a bit but thanks to you I've already got multiplayer running. I tried adding a "leave lobby" and "leave game" button myself, but it's still to much for me. Especially the fact that if the host leaves that you need A. Host migration or B. force quit everyone back to main menu. I'm also thinking of just stopping the game and returning everyone to lobby when one player leaves, since it's a 1vs4 game.
But could you perhaps make a tutorial about that? A leave lobby and leave game button? I've been searching and asking people for 5 days now but no one seems to be able to help me :(
Been trying to figure that out myself...
You should set the Steam Mulitplayer Tutorial playlist to automatically sort from oldest to newest, it currently is all over the place and will always happen again if you don't set the sorting of it.
I made this playlist so I can find them easily if I need it. But it is public, so you can save it too :)
ruclips.net/p/PLmMS--T1mpeGNrVYu9L97fL7ks7yegWHN
Nice tutorial! But I have a question. In CharacterCosmeticsController we added Steamworks and Mirror libraries, but never used it. Will we be using it in the next tutorials? Because right now they seem unnecessary and I want to remove them from top of my script :D
Yeah no remove them there's no need for them. i think i kept that in because originally I was going to do something but then edited it out.
amazing
For some reason the color is never set, it just uses the color in the 0 value.
I downloaded the source files and ran that project and it also does not work there. I think the issue is that "CmdUpdatePlayerColor(int newValue)" does not appear to ever be called but not sure where to put that.
I posted a comment that should help you out.
@@WolfServant Posted a comment where? I don't see anything else from you in the comments on this video
@@WolfServant Nevermind I got it working. I added the FindLocalPlayer method and varibales from the lobbycontroller script into the CosmeticController and added a line to call the command from the playerobject controller: LocalplayerController.CmdUpdatePlayerColor(currentColorIndex);
@Frosty could you fully explain what you did to solve this?
@@Shadowkiwi Could you fully explain what you did to solve this?
I have a question, how can one player trigger another player's component. I will be very happy if you answer
1:35
UsingEngine.UI
Steamworks
... And finally using Mirror
Proceeds to use Microsoft instead hahahah
Nice video btw, I think multiplayer is something that is not taught much, thanks.
yeah i changed it after but forgot to show it hahah. thanks a lot !!
Hey i really like your vids coups you Mauve make a tutorial on how to make a prophunt game?
YEEEESS FINALYYY
The color dont change its stuck on blue even if i change in the lobby its still stuck how can i fix it?
Hello can u PLZ do an tutorial about player health sync ♥
Hey Zyger, I tried to make that if one player picked a color, others player can't pick it. But I can't make it work? How can I do this?
You would have to keep track of what color someone picked, probably like an I'd for each color index. That data would need to be sent to every user so I'd probably send the data when somebody locks in a color.
I'd then just make it so that if a player clicks on a color and its index is on that list it doesn't let them pick it. Of course you can make it looks more polished with a visual indication or something.
It shouldn't be too difficult and there's multiple ways to go about it but the one I proposed here should be quite straight forward.
how to make backbutton in lobby?
How would one go about creating a leave function to leave the lobby?
there are different ways but I posted a solution in my discord server
hi how do I add the libraries: Steamworks and Mirror
google them
i cant find where were syncing the player color int for the life of me, if anyone knows please help
edit; i know that its a syncvar but where are we making it equal to the Character select's current color index?
found it, i added playerMat = PlayerPrefs.GetInt("currentMatIndex", 0);
to the update method
now both players are the same color when im scrolling through the list tho, progress
Got it! i called the CommandUpdatePlayerColor(); in the update method, then i passed in the colorIndex from the CharacterCosmeticsScript, so CommandUpdatePlayerColor(characterCosmetics.colorIndex);
this seemed to fix my problem, though, it will be updating the color every frame so i recomend making an if statment to check if ur out of the character customization screen, and then disabling it if u are
also discard my previous comment about the PlayerPrefs in the update method, doesnt work
Hope i Helped Someone out!
Zyger still play indie games?
do you need to purchace anything to test these
no you dont. You just need to install steam which is free. Bare in mind though if you do actually plan to release your game, purchasing a steam application would be wise, but still not 100% necessary.
thank you@@ZygerGFX
player select pls)
When new tutorial?
Soon just working on some atm
@@ZygerGFX What will it cover?
我的颜色为什么设置不上,up能修复这个bug吗? 这对我很重要! 谢谢。 你这个善良美丽的女人。
First!
Second!
First comment!