Reputation: 83
I'm trying to use a fixed background. I added the image as a child of camera and sized it to fill view of camera. It seems good in unity player however when I run it on my android devices, background seems short. I see some blank space in left and right sides of the screen. Orthographic size is 6.
Upvotes: 0
Views: 4443
Reputation: 681
This will position a plane or quad and scale it so it will fill the screen. It works both in orthographic and perspective. Orthegrphic size doesnt matter.
step 1 - Create a Plane object in your scene.
step 2 - Add this script to the object created.
step 3 - Script will auto resize and position at the near clip
using UnityEngine;
public class FillScreenPlane:MonoBehaviour
{
public float lUnityPlaneSize = 10.0f; // 10 for a Unity3d plane
void Update()
{
Camera lCamera = Camera.main;
if(lCamera.isOrthoGraphic)
{
float lSizeY = lCamera.orthographicSize * 2.0f;
float lSizeX = lSizeY *lCamera.aspect;
transform.localScale = new Vector3(lSizeX/lUnityPlaneSize, 1,lSizeY/lUnityPlaneSize);
}
else
{
float lPosition = (lCamera.nearClipPlane + 0.01f);
transform.position = lCamera.transform.position + lCamera.transform.forward * lPosition;
transform.LookAt (lCamera.transform);
transform.Rotate (90.0f, 0.0f, 0.0f);
float h = (Mathf.Tan(lCamera.fov*Mathf.Deg2Rad*0.5f)*lPosition*2f) /lUnityPlaneSize;
transform.localScale = new Vector3(h*lCamera.aspect,1.0f, h);
}
}
}
Upvotes: 3