- Home /
resolution/aspect ratio independent bg texture
Hello,
I'm trying to make a resolution/aspect ratio independent GUI and I want to have a image that is behind a GameObject that is in the scene. Here is what I have tried.
Make it a GUITexture. That didn't work because it wouldn't float, plus it covered the GameObject in the scene.
Just make it a regular object and place it just above in Y space (top down layout). This was successful in being behind the GameObjects but was not when the scene changed it's aspect ratio.
Write a script that will look at the Screen.width and Screen.height and pass the desired vector3 placement through a camera.ScreenToWorldPoint() operation so that it will find the correct X and Z values to match the other GUI elements (which I have successfully placed and scaled. I am missing something here, and I haven't found anything in the forums that deals with this specific issue. Here is the code for the failed attempt.
var prefab:GameObject;
var quickSelectBackPlacementX = (Screen.width * 0.9);
var quickSelectBackPlacementY = .01;
var quickSelectBackPlacementZ = (Screen.height * 0.9);
var quickSelectBackPlacement = Vector3(quickSelectBackPlacementX,quickSelectBackPlacementY,quickSelectBackPlacementZ);
var quickSelectBackCoord;
function Start()
{
quickSelectBackCoord = camera.ScreenToWorldPoint(quickSelectBackPlacement);
quickSelectBackCoord.y = quickSelectBackPlacement.y;
var quickSelectBackPos = Vector3(quickSelectBackCoord.x,quickSelectBackCoord.y,quickSelectBackCoord.z);
var quickSelectBack = GameObject.Instantiate(prefab, quickSelectBackPos, Quaternion.identity) as GameObject;
}
Does anyone have any ideas about how this effect might be achieved? All ideas are welcome.
Best Regards,
Steve
Also, please let me know how I can format my code better!
Answer by ninthjarl · May 08, 2012 at 12:15 PM
Hi, I do not understand your exact implementation but if your game object is always facing the camera then you could try using a billboard behind your gameobject. I have never implemented that in Unity but it is basically a plane that always faces the camera in 3D.
All the best.
Your answer