Search Unity

Camera, Screen, Other

Discussion in '2D' started by JeremyBenson11, Oct 27, 2014.

  1. JeremyBenson11

    JeremyBenson11

    Joined:
    May 9, 2013
    Posts:
    37
    Hey,

    I know this has been done to death, but like others I'm struggling with it. I'm making some headway, but I was hoping some people could help me with specific questions. It seems no matter what I watch I can't learn it, lol. Not to mention being slow with the trickier math, it's been a pain.

    I've got sprite tiles that are 40x40. I'm not sure if they're bad sizes for unity or not...

    They seem to be displaying right across the board. I get 40 pixels viewing the image in my browser (just right click open with, not making a browser game), 40 pixels when I play the scene in Unity, 40 pixels playing on windows stand alone set with smallest screen resolution, and 40 pixels when on stand alone's highest resolution setting.

    I've attached some pictures to show this..

    My pixels to unit setting is default 100, my camera is orthographic, and I have a script on it.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class camerascript : MonoBehaviour {
    5.  
    6.     public GameObject player;
    7.     private Transform playerTransform;
    8.     // Use this for initialization
    9.     void Start () {
    10.  
    11.         playerTransform = player.transform;
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update () {
    16.  
    17.         transform.position = new Vector3 (playerTransform.position.x, playerTransform.position.y, transform.position.z);
    18.  
    19.     }
    20.  
    21.     void Awake(){
    22.  
    23.  
    24.     camera.orthographicSize = ((Screen.height / 2.0f) / 100f);
    25.  
    26.     }
    27. }
    To be honest I don't really understand what this formula is doing...

    camera.orthographicSize = ((Screen.height / 2.0f) / 100f);

    I see camera size (I assume is size in the inspector) is equal to half the screen height divided by Unity's pixels per unit? Not 100% sure about it...

    umm....

    What I was trying to set up wasn't a scene where the camera followed the player, but just a simple jump tile situation. With the player as the yellow tile, and there would be say two tiles to jump up on, three across, and then the finish....

    The problem is when I originally started I had everything looking good in the editor, while not paying attention to settings, but then builds were horrible. I didn't understand what was happening between what I had in unity and the relationship with it between picked resolutions in the stand alone player.... Then I went on this quest to learn 'pixel perfect camera'.. not sure what I'm dong right or wrong, because I only understand pinches of the process here and there, lol...

    I guess some questions are

    1) How do I get my level to fit one camera scene on all the resolutions, or is this possible? In other words the camera size is the level size and there is no scrolling, but everything is on screen no matter what resolution is picked in the stand alone player.

    2) If I was to design a game to fit a certain resolution and I wanted this to be strict is there a way to disable all other options in the stand a lone player....

    umm 3 is dumb...

    3) If I solved 1 I wouldn't have to worry about 2 right? lol.
     

    Attached Files:

    Last edited: Oct 27, 2014
  2. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    Camera Ortho size is the number of world space units across half of your screen vertically. Strange concept.

    1. If you want to fit your entire scene then don't adjust the Ortho size. You can't have pixel perfect art this way though.
    2. It's a bad practice to have fixed resolutions. But you can definitely disable fullscreen mode, window resizing and set. resolution in the player settings.
    3. What's 3 exactly?
     
  3. JeremyBenson11

    JeremyBenson11

    Joined:
    May 9, 2013
    Posts:
    37
    Oh three doesn't matter...

    world space units? Is that pixels to units? It's set to 100 so it's saying a size five camera will fit 500 pixels across half the screen? so the entire camera at 5 is 1000 pixels across?

    Clearing this up would be awesome...

    It's bad practice to have fixed resolutions...

    I don't understand how to not have fixed resolution... If I have everything in one scene and they don't have the right resolution picked the graphics get stretched off the screen..

    Thanks for the reply. If you and others could help me clear up pixels to units, what the camera sees at what ortho size, and resolution I would be really grateful.

    :)
     
  4. JeremyBenson11

    JeremyBenson11

    Joined:
    May 9, 2013
    Posts:
    37
    I guess one of my major problems of misunderstanding is why the resolutions picked from the resolution dialogue in a stand alone cuts off graphics and how to overcome it.

    If I want everything to fit in one camera scene I don't mess with the orthographic camera size, but if I do that the smaller resolutions still aren't going to show everything...

    Is there a way to solve that?