Screen.width and Screen.height

using UnityEngine;

using System.Collections;

public class Background : MonoBehaviour

{

void Start ()
{

	Vector3 scale = transform.localScale;
	scale = new Vector3 (Screen.width, Screen.height, 0);
	transform.localScale = scale;
}

}

when i press play, the x and y for my object becomes 600 for x and 288 for y. The scale is way too big. why isnt it working?

I think this is what you want.

float targetWidth = Screen.width;
float targetHeight = Screen.height;

Vector3 currentWidth = yourObject.GetComponent().bounds.size.x; 
Vector3 currentHeight = yourObject.GetComponent().bounds.size.y; 

Vector3 scale = yourObject.trasform.localScale;
 
scale.x = targetWidth * scale.x / currentWidth;
scale.y = targetHeight * scale.y / currentHeight;

 
yourObject.trasform.localScale = scale;

I used this post as a reference: Scale object to certain length - Unity Answers

Hey Hubert322

You can get the world size of an othero camera by using this code.

Vector2 camWorldSize = new Vector2();
camWorldSize .y = Camera.main.orthographicSize;
camWorldSize .x = Camera.main.orthographicSize * Camera.main.aspect;

The height is equal to the orthographic size of the camera and the width is that size times the aspect ratio of the screen.

It would be better to cache the camera component then use Camera.main but it gets the point across.

Regards,