- Home /
 
2D GAME (non UI object) for every pc resolution
Hi everyone! I'm making a game, but now i have a big problem ... the resolutions D: I've searched thousand of question about this problem, but i did not find no answer ... How i can make my game working with different resolution? Yes ... i'm using 2d sprites, but i can not use this object as UI elements ... how i can solve this? If you have any type of script that can scale 2d sprite in a scene according to resolution please post it D:
It wouldn't make sense to scale the sprites since in this case, with lower resolutions the distances between them would shrink which would potentially mess with the game logic, and I can't think of any game that does this. Ins$$anonymous$$d, chagne the camera's Orthographic size to take into account the new resolution. Check the User $$anonymous$$anual and Scripting API for more information on this variable.
I searched online and i found an old script and i modified it for current version of unity, but it doesn't works very well:
 using UnityEngine;
 using System.Collections;
 
 public class camera : $$anonymous$$onoBehaviour {
 
     public float twidth;
     public float ptu;
     void Start()
     {
     }
 
     // Update is called once per frame
     void Update () {
 
         int height = $$anonymous$$athf.RoundToInt(twidth/(float)Screen.width*Screen.height);
         GetComponent<Camera>().orthographicSize = height / ptu / 2;
     }
 }
 
                  Your answer