Should I be having the canvas inside of the player gameobject so it is his hpbar etc or does each user get the same scene replicated for themselves?
Unless you’re talking about multiplayer on 1 screen, then technically everyone has a copy of everything (that’s shared).
What values you show/update, etc are user depedent.
Imagine I was playing a game and you were another player. We’d both have a canvas with our health bar, but mine would be showing me my health and you yours.
i guess your players prefab for local and remotes are identical?
so i would do something like this:
void OnLoadPlayer(bool local)
{
if(local == false) return;
var uiHealthBar = Instantiate(Resources.load("UI/HealthBar")).getcomponent<UiHealthBar>();
uihealthbar.AttachPlayer(this);
}
so you have one canvas in Resource/UI/HealthBar.prefab this way your scene stay clean.
I’m talking about mmo type of multiplayer and ui.
So say I do in code :
castBar = GameObject.Find(“CastingBar”).GetComponent();
there would be no errors of everyone using the same canvas in the scene because its a duplicate for themselves and it finds the casting bar on their duplicate?
Also is it better to serialized field it instead of find it this way?
Yes, that’s how it’d be, if there was just 1 casting bar per scene. It would be for the player.
Yes, to your second question, too. Always avoid GameObject find if you can.
It was a way to hard code instead of using the inspector and there would only be one gameobject named CastingBar.
I’ve been trying to find information on serialized fields when I would want to avoid using them and why I would want to use them over hardcoding the find which would seem more reliable than something set in the inspector or atleast everything seems more setup in the code.
Well, a couple of issues with find are speed and potential errors. Since you pass a string, you might mistype it or rename the object. The speed issue is that it searches everything in the scene until it finds a match.
variables you assign in the inspector are a lot more reliable and a lot faster.
So the outside put into the inspector will always override default as well as start initializations?
inspector values will replace a class declaration line, but not something done in Start().
back to the ui, lets say I had a singleton class spellbook attached to the spellbook ui, this singleton has its own copy per person as well right, its no different?
Ya, it should be that way (as in you should make sure it’s so).
Like, on the client’s copy of the running game, only that local / client player should try to access “their own” stuff. Nothing is literally shared in a multiplayer game. Stuff appears to be shared, by passing data around…Right?
In other words, so long as you don’t let some other player (other than the client) access the client’s singleton or anything else exclusively theirs, everything should be okay
Hope that makes some sense.
Well I want to be able to access the singleton for spell/attack effects from other players however I want it to be only effecting that players spellbook they are attacking with the skill disable or similar.
Not sure I totally understand what you’re saying, sorry.
Are you currently working on the game? Is it working okay?
would each person get their own static singleton or would they all pull from the same static singleton.
If each client gets the singleton, everything should be okay so long as you aren’t trying to sync anything from it to everyone.
Clients can’t pull from the same static singleton. Which machine would host that singleton?
A better solution would have server react to changes in the world (e.g. player dies, respawns etc.) and transmit data to connected clients. Those connected clients would then update their singletons.
This way, you only transmit values only when they’re changed. And bandwidth is kept minimal.
I’m still at low level csharp learning quickly and networking has always been intimidating to me and I want to learn more about it.
I’m not sure what you mean by which machine hosting the singleton. The singleton would be attached to that player by being a part of his ui aka on his spellbook panel and I want each player to have his own instance of that spellbook for his own recharges/cast times to be altered during gameplay.
Is networking going to be hard to learn for an mmo?
A better question, Once I have the game in a single player state playable and setup to attack players or enemies will multiplayer implementation be complicated to learn?
Well, I will offer a general answer to that.
Before you learn networking for programming (and/or game making), you should learn programming. Do not try to program network stuff first… unless you’re just having a bit of fun. That’s up to you.
If you feel comfortable at making a game, and then want to make a network multiplayer game, then you should begin the game with networking in mind from the very beginning.
If you want to learn more about networking, and you are already somewhat decent at programming, I would suggest that you try some general networking (ie: not really try to make the game work).
If you only want to know a simple game for Unity, you can try their HLAPI and or LLAPI and see how that works.
This answer is pretty general, because I wasn’t sure about your experience, necessarily. And it’s all just my opinion, but hopefully it makes some sense.
I’m reaeding on unitys hlapi right now, would you recommend learning php and some mysql for saving stuff?
Well, like I said, my suggestion would be to make sure you’re okay with programming to begin with.
Then, if you’re trying the HLAPI just try some simple things like sending data back n forth that you can read (or execute methods or sync variables, in the case of the HLAPI).
As for php and mysql, I’ve never used either, but if they are something you need/want later, then I guess learning them would be important