- Home /
Make Object same Width and Height as the Perspective Camera size
Hello! I would like to fit an object (back wall) to the size of the camera, or better yet, to fit the size of the actual screen size. I have a code to position objects to the sides, depending on the size of the screen, but I want to make the back wall to cover exactly the background (width and height) depending on the size of the screen. Don't worry it wont change since I will block orientation and will be only for phones. But can't find how to make the background same width and height as the screen size.
My actual code`public class PositionObjects : MonoBehaviour { public GameObject WallLeft; public GameObject WallRight; public GameObject Floor; public GameObject WallBack; public GameObject Toilette; public GameObject ObjectSpawner; public float WallWidth;
void Awake()
{
WallLeft = GameObject.Find("WallLeft");
WallWidth = WallLeft.transform.localScale.x;
WallRight = GameObject.Find("WallRight");
Floor = GameObject.Find("Floor");
WallBack = GameObject.Find("WallBack");
Character = GameObject.Find("Player");
ObjectSpawner = GameObject.Find("ObjectSpawner");
WallLeft.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(-(WallWidth/2)*100,Screen.height/2,10));
WallRight.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width+(WallWidth/2)*100, Screen.height/2,10));
Floor.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2,0,10));
WallBack.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2,Screen.height/2,11.5f));
Character.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, 50, 10));
ObjectSpawner.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height+150, 10));
}`