Hello guys,
I have an orthographic camera in the scene, I have a plane with a texture attached, I was struggling to find out how can I make the background of my game Resolution Independent. By resolution independent, I mean to say that the background should be the same no matter what mobile device the game is played on. The game will be built in Portrait mode.
Any suggestions?
EDIT: This background is basically a car race track which will have 2d colliders to check if the car is hitting one of those colliders. I believe I cannot do this using a 2nd Camera, or can I?
I think Its not difficult task. All you have to scale your BG Image as the camera width and height. You can do it in your code.The problem is you can set height but not width in Editor as it always changes in every device. Here is a script to stretch bg as the resolution of any mob device in portrait mode.
using UnityEngine;
using System.Collections;
public class BGScript : MonoBehaviour {
SpriteRenderer sr;
void Start () {
sr = GetComponent<SpriteRenderer> ();
float xmas = Screen.width*Camera.main.orthographicSize*2.0f /(Screen.height*1.0f);
float yScale = Camera.main.orthographicSize*2.0f / sr.renderer.bounds.size.y;
float xScale = 0;
xScale = xmas / sr.renderer.bounds.size.x;
transform.localScale = new Vector3 (xScale,yScale,1);
}
}
Add it to your background object in Editor.