I tried to scale my background sprite to the screen resolution, but it doesn’t work.
What am I doing wrong?
using UnityEngine;
using System.Collections;
public class ScaleBackground : MonoBehaviour {
GameObject Background;
// Use this for initialization
void Start()
{
Background = GameObject.Find("Background");
float windowWidth = Screen.width;
float windowHeight = Screen.height;
float spriteWidth = Background.transform.GetComponent<BoxCollider2D>().size.x * 100;
float spriteHeight = Background.transform.GetComponent<BoxCollider2D>().size.y * 100;
float backgroundWidth = windowWidth / spriteWidth;
float backgroundHeight = windowHeight / spriteHeight;
// Scale Sprite
Background.transform.localScale = new Vector3(backgroundWidth, backgroundHeight, 0);
}
// Update is called once per frame
void Update () {
}
}