Home > Software design >  Struggling with Mobile build on phone, looking different on phone and Pc
Struggling with Mobile build on phone, looking different on phone and Pc

Time:05-19

Firstly I'm still fairly new to coding, saw people making games and fell in love with the idea of making your own game. So the past few months I've been learning unity tutorials and practicing basic games. I've come so far to be basically done with my first game. Everything is ready and I want to load and post it on playstore, but there's one last issue. When I run it on Unity on my pc it looks perfect but I loaded it onto my phone and the UI and some objects is either not showing or looking different than on the pc.Example1Example2Example3 These are examples of my problem. The IMG above is the way it should look like and the one underneath is how it shows on my phone when loaded.

CodePudding user response:

That's because of your Canvas settings & your UI GameObjects Anchor. But I think the easiest way to solve this for you - because you don't have that much experience about it - is to separate canvases for mobile & pc. This is the code:

private void Start() 
{
    if (Application.platform == RuntimePlatform.WindowsPlayer) // If your game's running on android
    {
        pcCanvas.SetActive(true); // Use PC designed canvas
        mobileCanvas.SetActive(false); // Disable Mobile designed canvas
    }
    else // Your game is running on mobile
    {
        pcCanvas.SetActive(false);
        mobileCanvas.SetActive(true);
    }
}

Add this to a GameObject, Design 2 Canvases & assign them to script. (This will be a litte complicated, but will work) This link for more info

But if you want to use 1 canvas, you have to set its settings & its GameObjects anchors.

CodePudding user response:

It doesn´t look the same, due to the different resolutions.

Try to use a Canvas Scaler component. Set a reference resolution and the mode how you want to scale it.

If you want your UI elements to be anchored to the center/top/left etc. you should also set the anchor points. Here is a good Tutorial

A good way to instantly check the result is the "device simulator" It is a unity package

  • Related