Multi Resolution Textures for Multi Resolutions

Hi there. I’m wanting my PC game to have multiple resolutions so that when the user chooses their resolution, an image made specifically for that particular resolution will be displayed on the screen as the main background 2D image.

At the moment I have my images within the resources folder and am accessing the images as a www file type.

I have put this script on to a Cube gameobject so far and it does display by accessing the renderer, but of course if I change the image to a different resolution type it doesn’t really make a difference with alignment. This is where I don’t know where to go, because I’m not sure which Gameobject type I should use for what I’m trying to do (stick to the cube, empty gameobject with shader and renderer? A plane? A quad?). Is there a type of gameobject to easily load up the image and display correctly to the resolution in relation to the main camera, or a simple script to do this?

Here is my script for accessing the image and it being placed on the cube:

using UnityEngine;
using System.Collections;

publicclassImageBackground:MonoBehaviour
{

publicTexture2DscreenImage;

SpriteRendererrend;

publicWWWpullImage;

voidStart()
{
rend=GetComponent();

screenImage=newTexture2D(128,128);
Rendererrenderer=GetComponent();
renderer.material.mainTexture=screenImage;

screenImageShow();
}

voidscreenImageShow()
{
pullImage=newWWW(“file://”+Application.dataPath+“/Resources/ScreenImage.png”);

//rend.sprite=loadImage;

pullImage.LoadImageIntoTexture(screenImage);
}
}

I have been searching for a while now for solutions to this problem, and there are solutions, but I don’t know how to implement them properly because my circumstances are slightly different and can’t work out how to alter the code.

I am new to programming so any help will be greatly appreciated.

Thanks

Runtyboy

That will not work when you build your game. The resources folder will not be a folder when the game is build.
You would have to use this function to load your image:
https://docs.unity3d.com/ScriptReference/Resources.Load.html

Personally i would vote against using the resources folder and just use a array with all the images and pick the correct one at run-time out of it.

my recommendation would be:
Make a canvas with the Render Mode Screen Space - Camera.
Set the camera that you set to render that canvas with a low depth value so it will be in the background.
Then you can set a image in the canvas and then put the corresponding background at run time into that image.
You can set the image to be stretched always to the full canvas so it should always fill the background.

1 Like