I would like my background to adapt to changes resolutions in mobile devices.
Can check in images, i need layout only fit the main camera resolution
What can i do ?
I would like my background to adapt to changes resolutions in mobile devices.
Can check in images, i need layout only fit the main camera resolution
What can i do ?
Do you want to change the aspect ratio of the image?
In other words, you want to have your image completely fill your camera view port, Either in landscape or portrait mode? And you don’t mind it’ll be deformed?
Only in portrait mode…
You’ll have to explain a bit more what result you want. Are you trying to support both landscape and portrait, and have your background look correct in both?
-sam
I think this code will do what you want:
float spriteActualWidth = renderer.sprite.bounds.size.x * renderer.transform.localScale.x;
float spriteActualHeight = renderer.sprite.bounds.size.y * renderer.transform.localScale.y;
float widthMultiplyer = (Camera.main.orthographicSize * Camera.main.aspect) / spriteActualWidth;
float heightMultiplyer = (Camera.main.orthographicSize) / spriteActualHeight;
renderer.transform.localScale = new Vector3(widthMultiplyer * renderer.transform.localScale.x * 2, heightMultiplyer * renderer.transform.localScale.y * 2, renderer.transform.localScale.z);
Let me know if I am wrong.