how to dynamically stretch an gameobject across a screen

I have a GUI Orthographic camera which display a dynamic black box (for dialog), the GameObject’s scale is 1,1,1 which is a perfect square. The game screen will be dynamic in width, so sometimes it might be 1024, other times it might be 1920,

I am trying to determine an algorithm that will stretch this box according to the user’s screen that it covers the entire width. Again, this is a GameObject, I’m not using GUI.DrawTexture

Well you could check the screen coordinates, convert them to world coordinates and change the size x and y of the gameobject to match the x and y coordinates you got of the screen, or something like that :o

I guess the issue for me is I’m used to working with width and height, ideally what I would like to do is
gameobject.width = Screen.width

but in Unity there is only scale

is there a quick mock up or pseudocode you could display to help me grasp what you are talking about?

Try this…

gameobject.localScale = new Vector3(Screen.width, Screen.height, 0);

well you get the idea. It will scale the x axis of gameobject to screen width, y axis to sreen height and z axis to 0. :slight_smile:

If you want DYNAMIC BOX that will fill whole screen no matter on resolution, then you have to do this

using UnityEngine;
using System.Collections;

public class MineMenu : MonoBehaviour 
{
	void OnGUI ()
	{
		GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "This is the title");		
	}
}

You should set sizes of box when you’re making the box, don’t use variables because you can’t set “Screen.width” in class (I mean I had problems with that) if you have public variable maybe your settings in inspector overrides settings in code
like this:

....
public class MineMenu : MonoBehaviour 
{

   [COLOR="red"]private Rect BOX = new Rect(0, 0, Screen.width, Screen.height);[/COLOR]

	void OnGUI ()
	{
		GUI.Box([COLOR="red"]BOX[/COLOR], "This is the title");		
	}
}

that is what I know about it, I had problem that I couldn’t make window for full screen