Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UI Overlapping When Someone Joins Game (Mobile FPS)

Discussion in 'Multiplayer' started by ParkSolomon, Oct 2, 2016.

  1. ParkSolomon

    ParkSolomon

    Joined:
    Oct 2, 2016
    Posts:
    1
    Hey I have a weird problem going on with my player UI Canvas. I have a network manager sync my player movements across the network working just fine. However since I'm making a mobile fps there is UI on screen that helps you move around and navigate, but whenever someone joins my room the UI overlaps the one currently shown on my screen making it hard or impossible for me to control my character and in some cases I can control there character too.

    This is how the scene setup is looking like - scene.PNG

    This is me playing without any other players connected (works just fine) - mobing.PNG

    This is the result when two or more player join (UI overlaps and unable to control local player) - moving with two.PNG

    As you can see there is two joysticks instead of one, and I'm unable to control my character correctly sine there's two UI Canvas. Help would be gladly appreciated thanks!
     
  2. Chinmay_Gawande

    Chinmay_Gawande

    Joined:
    May 28, 2017
    Posts:
    4
    You can try with GUI . It is intermediate solution but it works on network.
    void OnGUI(){
    if(GUI.Button(new Rect(0,0,50,50),"Button")){
    if(isLocalPlayer){
    //Do What You Wanna Do
    }
    }
    }
    I have not tried it with UI . Test it with UI if You Want :)
     
  3. RaghavBharathi

    RaghavBharathi

    Joined:
    Mar 29, 2020
    Posts:
    3
    1) Instead of making canvas a player object, make panel a player object, so that all your players are different panels under same canvas. Now, when object are under same canvas, they ray casting order is determined by the order in hierarchy.

    The objects that are lower in the hierarchy occlude those that are higher. So, what you can do is moving your player object to the lowest position in objects hierarchy, so that it will occlude all other players. This can be done using Transform methods SetSiblingIndex and GetSiblingIndex, like

    Code (CSharp):
    1. transform.SetSiblingIndex(100000/*some big number*/);
    2) Disable raycasting on all other players - what if you can click some component on canvas or not is whether it is a raycast target. Images and Text components can be raycast targets, or more generally any component that inherits from Graphics. You can iterate over all components of type Graphics in all players except the local player and mark
    Code (CSharp):
    1. raycastTarget = false
    .
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Ignoring the fact that this thread was last active 3 years ago, why would you want your UI on the player object anyway?

    Much better to keep it separate, and then you'll only ever have the one instance of the UI no matter how many players are connected. When the local player is instantiated you just hook it up to the UI.