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

Question Change video logo depending on screen resolution

Discussion in 'Editor & General Support' started by Vsevolod777, Mar 7, 2023.

  1. Vsevolod777

    Vsevolod777

    Joined:
    Apr 18, 2022
    Posts:
    8
    Hello! I'm building my first mobile game in Unity and I'm trying to figure out how to make a responsive bitmap logo and also an initial splash-screen.

    After the Unity logo, I load a separate scene with a video player that plays 16:9 (1.78) video by default.

    I want to check for different mobile phone screen ratios and enable a specific video player depending on the screen ratio. A similar technique is implemented in eFootball and FIFA.
    Their splash screen works great on all resolutions.

    I spent a whole day to find the information, but I never figured it out. I have:

    public GameObject Video43;
    public GameObject Video169;
    public GameObject Video54;

    and a small condition:

    voidStart()
    {
    if (Screen.height / Screen.width <= 1.33)
    {
    Video43.SetActive(true);
    debug.Log("4:3");
    }
    if (Screen.height / Screen.width <= 1.78)
    {
    Video169.SetActive(true);
    Debug.Log("16:9");
    }
    if (Screen.height / Screen.width <= 1.25)
    {
    Video54.SetActive(true);
    debug.Log("5:4");
    }
    }

    If I check all the ratios 1.33 or 1.25 in a row, then all three video objects are turned on simultaneously. Works also <. But for some reason == doesn't work.

    When I write "else if" after the first if, only the first line is included by default. That is, the conditions for checking the screen ratio do not work at all.

    Perhaps I didn't fully understand C#. Overall, I'm happy that I chose Unity. I implemented a full-fledged game menu and I want to resolve this issue as soon as possible.

    I am hope for your help! Thank you!
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    Disable the other gameobjects in the 2nd and 3rd gameobject, then only the wanted one is active
     
    Vsevolod777 likes this.
  3. Vsevolod777

    Vsevolod777

    Joined:
    Apr 18, 2022
    Posts:
    8
    Thanks for the answer! Do you mean disable the other two in the hierarchy window? All three empty game objects with a video player component are in the same Canvas. I disabled two and it didn't work. The one whose code is at the very top is included.
     
  4. Vsevolod777

    Vsevolod777

    Joined:
    Apr 18, 2022
    Posts:
    8
    My reference resolution in game is 1920x1080 (1.78). My monitor also has an aspect ratio of 1.78. I performed the following in-game resolution check with the following script:
    Resolution[] resolutions = Screen.resolutions;
    // Print the resolutions
    foreach (var res in resolutions)
    {
    Debug.Log(res.width + "x" + res.height + " : " + res.refreshRate);
    }
    In the console, I see the output from the "Simulator" window. If I put the iPhone 13, then I see the resolution of the iPhone, not my monitor.
     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    That's why you disable the gameobject from the top in the later if statements
     
    Vsevolod777 likes this.
  6. Vsevolod777

    Vsevolod777

    Joined:
    Apr 18, 2022
    Posts:
    8
    Thank you! Could you guide me step by step how to solve my issue in this question? I don't quite understand how to solve this. I disabled two other objects, disabled all three objects, but the code still does not work.
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    Code (CSharp):
    1. public GameObject Video43;
    2. public GameObject Video169;
    3. public GameObject Video54;
    4.  
    5. and a small condition:
    6.  
    7. voidStart()
    8. {
    9. if (Screen.height / Screen.width <= 1.33)
    10. {
    11. Video43.SetActive(true);
    12. //Vid169 srtsctive false
    13. //Vid54 setactive false
    14. debug.Log("4:3");
    15. }
    16. if (Screen.height / Screen.width <= 1.78)
    17. {
    18. Video169.SetActive(true);
    19. //Video43.setactive false
    20. //Video54.setactive false
    21. Debug.Log("16:9");
    22. }
    23. if (Screen.height / Screen.width <= 1.25)
    24. {
    25. Video54.SetActive(true);
    26. //Set 169 and 43 false
    27. debug.Log("5:4");
    28. }
    29. }
     
    Vsevolod777 likes this.
  8. Vsevolod777

    Vsevolod777

    Joined:
    Apr 18, 2022
    Posts:
    8
    Thanks for your code, DevDunk! I have corrected. My Unity version is 2021.3.20f1. In my case, the following condition is triggered:

    if (Screen.width <= 1920 && Screen.height <= 1080)

    Or

    if (Screen.width / Screen.height <= 16.9)

    It seems to be all working. In the first case, it is simply unrealistic to drive in all the resolutions of the world's phones in pixels and make splash screens for them. In the second case, it also seems to work. I will test.

    I tried to write:

    if (Screen.width <= 1.78 && Screen.height <= 1) but that doesn't work either.

    I want to understand: are the Screen.width and Screen.Height values taken from the "Game", "Simulator" window or my monitor or phone screen?

    I also found (Camera.main.aspect >= 1.7), but it seems these values are taken from the Canvas Scaler for the specific camera. I'm not entirely sure that this will determine the device.
     
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    Why don't you just make 1 video which is tall, without much required info happening outside of the middle? Then just put the camera so it crops off the unneeded bits?
     
    Vsevolod777 likes this.
  10. Vsevolod777

    Vsevolod777

    Joined:
    Apr 18, 2022
    Posts:
    8
    Yes, thank you! I thought about it in advance. I see the latest iPhones are up to 3k resolution.

    I found this video on Youtube launching Konami's eFootball 2023 mobile game.



    You can see how it works there. In my game, I also decided to make a logo and Splash Screen as well.

    When I run this game on my Asus ROG Phone 5s, I see their video logo is a bit blurry. They probably zoom in on their videos on big screens. Then their splash screen is cut off a bit around the edges. They probably have a splash screen resolution of 2440 in width, and I have 2448.

    Maybe you're right. I need to render a large video from 2.8k to 4k. And then through the condition to make another version of the logo separately for tablets.

    I think it's not a problem. I like Unity. Powerful, functional engine.

    Now I have to decide whether to switch my game to URP. I have heard that URP has some issues with iPhones. Perhaps these problems have long since been fixed. With Android, I am absolutely calm.

    Thank you for your help!