Search Unity

player only vs all players affected

Discussion in 'Multiplayer' started by xeonheart, Dec 29, 2021.

  1. xeonheart

    xeonheart

    Joined:
    Jul 24, 2018
    Posts:
    219
    Hello,

    so just a quick question, and probably easy one to, so I am using Unity, with playfab and Photon for a mobile game, and in short, there are some things that the player will need to be affected only, and some things that the PLAYERS that is in the game will need to be affected... example:

    player that reaches a certain point, and has certain things done, will have a certain pop up screen... that screen wouldnt have to be a prefab, and more importantly, wouldnt have to part of the player prefab, or should it? there will be about 10-18 pop ups, that will only be by player depending on tasks done or points etc.? how would you accomplish this, by the game itself having the popups, or having the pop-ups in the player prefab?

    as for things affected by all players, example, maybe a NPC or maybe a enemy, that runs around trying to get any player, that would require a prefab correct?

    any more info about photon and prefabs or multiplayer doc would be great :)

    thanks in advance.
     
  2. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I would never make UI part of a player prefab. You should strive to keep your UI totally decoupled from other game prefabs/logic. As you say you should have "the game itself having the popups". You will likely want a UI prefab, just not as part of your player prefab.

    NPCs that are networked would need to be prefabs in a Resources folder so you can properly instantiate them on all clients.
     
  3. xeonheart

    xeonheart

    Joined:
    Jul 24, 2018
    Posts:
    219
    AWESOME big thank you toddkc, didnt think about making a prefab UI, that would make sense and even better more organized. thanks :) I will see if there are any good examples or tutorials online that can help with the UI prefab :)

    Also makes sense for the NPC's to be prefabs... honestly there would be probably maybe 10-12 of them at most... so hopefully it wont be that resource/network intensive, its so all clients know where the NPC's are, and all can interact with them when the NPC comes in contact with them.
     
  4. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    UI is pretty game-specific. I don't have any tutorials I recommend. I would look for "decoupled ui" or "event-based ui". If you find a tutorial that has a health bar on the player prefab look for a better one :D
     
  5. xeonheart

    xeonheart

    Joined:
    Jul 24, 2018
    Posts:
    219
    cool thanks, i will look it up, thank you again toddkc, one last question,

    you mentioned that "I would never make UI part of a player prefab"

    so would I just make a Player Prefab, that would have the sprite renderer/animation,

    but I have a script that controls the "Player" prefab on the prefab itself, wondering i I should move it on the canvas of the UI or keep it on the player prefab? just your thoughts or experience?
     
  6. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    The script that controls the player should be on the player prefab, yes. Player-logic goes on the Player Prefab, UI-logic goes on the UI Prefab. Ideally, anyways.