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. Dismiss Notice

Question Change camera distance based on screen width

Discussion in 'Scripting' started by Phoenix248, May 18, 2023.

  1. Phoenix248

    Phoenix248

    Joined:
    Sep 20, 2019
    Posts:
    51
    Hi everyone!

    I'm trying to make the GameObjects of my game to fit the screen width at different resolutions, but I'm struggling to calculate the correct Z distance of my camera. The goal is to achieve something like this:

    Example_Zdist.png

    So the camera should be closer or further away from the GameObjects depending on the screen width. Any ideias on how to calculate de Z distance so the GameObjects fill the entire width?
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,040
  3. Phoenix248

    Phoenix248

    Joined:
    Sep 20, 2019
    Posts:
    51
    Exactly what I needed, thanks!