I’m making a 2D game that auto-resizes some of the game elements like the foreground and background depending on the resolution of the screen. I am doing so with this Pixel Perfect Camera. I need help because I am trying to switch scenes and whenever I switch out of this scene and switch back into it, the camera zooms again and messes up my entire game. I guess I need to find a way to reset the camera so that when I come back into the game it can resize itself. I’m sure there is a better way to do this, but I can’t think of it so any and all feedback is appreciated!! Thank you!
using UnityEngine;
using System.Collections;
public class PixelPerfectCamera : MonoBehaviour {
public static float pixelsToUnits = 1f;
public static float scale = 1f;
public Vector2 nativeResolution = new Vector2 (240, 160);
void Awake () {
var camera = GetComponent ();
if (camera.orthographic) {
scale = Screen.height/nativeResolution.y;
pixelsToUnits *= scale;
camera.orthographicSize = (Screen.height / 2.0f) / pixelsToUnits;
}
}
public void Reset(){
}
}
*Sorry if I messed something up this is my first post.
2195722–145721–PixelPerfectCamera.cs (473 Bytes)