Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Client overrides Host's Inputs

Discussion in 'Multiplayer' started by GoDJaMMing, May 29, 2018.

  1. GoDJaMMing

    GoDJaMMing

    Joined:
    Feb 4, 2014
    Posts:
    7
    I'm familiar with UNET @ computer games.

    Thing is, i'm switching to Android thus making my own Joysticks (left for move, right for shoot u know the kind of game i'm doing).
    I always resolved clients problems with isLocalPlayer so everyone moves its own player.

    The problem, is that by adding Joysticks Images under Canvas with its own Scripts to handle movement works fine when single player, but when hosting, im ok till a client connects. From that very moment, client gets all inputs and host cant do a single thing.

    I can't have multiple networkidentities, so it's not possible to check for isLocalPlayer on inputs since they are children.
    I made some workarounds but it didnt go well.

    Any thoughts? Will be pretty much apreciated since this is a final project and got little to no time.
    Thanks
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'd separate your input controller object from the player prefab. Just have your input object script(s) get a reference to the local player to control it.
     
  3. GoDJaMMing

    GoDJaMMing

    Joined:
    Feb 4, 2014
    Posts:
    7
    Can you explain a little more? Cause Right Joystick has a reference to player and it gets bugged when another player joins the room. Even as child, I tell it thru GetComponentInParent and with transform.parent and still joystick controls another player.
     
  4. GoDJaMMing

    GoDJaMMing

    Joined:
    Feb 4, 2014
    Posts:
    7
    bump....
     
  5. GoDJaMMing

    GoDJaMMing

    Joined:
    Feb 4, 2014
    Posts:
    7
    Nevermind, got it working thanks twice to Joe-Censored @ this thread : https://forum.unity.com/threads/multiplayer-canvas-ui.503123/

    In other words, deactivate Canvas child in Player Prefab, and add this to the Player's script :
    Code (CSharp):
    1. public GameObject PlayerCanvasObject;
    2.  
    3. void Start()
    4. {
    5.     if (isLocalPlayer)
    6.     {
    7.         PlayerCanvasObject.SetActive(true);
    8.     }
    9. }
    10.