Search Unity

Multiplayer Canvas UI?

Discussion in 'Multiplayer' started by spinteractive, Nov 4, 2017.

  1. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    I am using a canvas UI on a Unity Multiplayer. Basically, I need controls on to move and shoot the player and I need them to be buttons on my touch screen.

    When I start the multiplayer as Host my buttons work. Then I start a Client and the Host buttons stop working (and the client buttons work). I imagine this is because there is one EventSystem and I assume it gets taken over by the client.

    Anyone know how I should handle this?
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    UNET doesn't do anything with your UI. Read through the UNET manual, my guess is that you are missing 'if isLocalPlayer' when doing your movement.
     
  3. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    I am using isLocalPlayer. I'm having problems with the Canvas UI Buttons as I mention above. The buttons work for the server, then when I add a client, they only work on the client. I am attaching the Canvas UI to the player prefab used by the network manager
     
  4. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
  5. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Got it! I de-activated the canvas on the player prefab, and simply did the isPlayerLocal check to activate it! –
     
    nagybalintgyorgy likes this.
  6. harikrishnan_annappilly

    harikrishnan_annappilly

    Joined:
    May 18, 2018
    Posts:
    1
    @spinteractive Me too having the same issue. I just dont know how to do it properly can you please share the script or the project. it will be a great help for Me and those who gonna face this issue in future. Thank you
     
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    If the canvas is on the player prefab, you just need to make sure you disable it when your player is instantiated if isPlayerLocal is false, otherwise you'll have a canvas enabled for each character object in the scene, and you don't want that to be the case for the remote player objects.
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If your canvas is on a child object of the Player GameObject, you can try something like this where you disable the canvas object by default in the prefab, and if isLocalPlayer is true you enable the object. Basically what @Munchy2007 was getting at, though I prefer having it already disabled and enabling if isLocalPlayer is true rather than the reverse, but you can try both ways.

    Code (csharp):
    1.  
    2. public GameObject PlayerCanvasObject;
    3.  
    4. void Start()
    5. {
    6.     if (isLocalPlayer)
    7.     {
    8.         PlayerCanvasObject.SetActive(true);
    9.     }
    10. }
    11.  
     
    rafaelbarbosa152 likes this.