- Home /
Camera placement / size behavior
im totally lost here...
[url]http://img41.imageshack.us/img41/5498/unity1.jpg[/url]
as you can see, i got a minimap going on in the upper corner wich works great and all, just had a second camera put up and scaled it as you can see in the inspector,
my problem is that i want people regarding of resolution to have the same SIZE of the minimap window, and only the locations move accordingly,
but when i change screensize this happens
[url]http://img96.imageshack.us/img96/5171/unity2.jpg[/url]
it gets all thin (reacts same way in a build and) i want a fixed size, but the placement will have to be the upper right corner always, so 800x600 and 1920x1080 will have same size of minimap (like the way GUI reacts to screen size change)
thanks alot in advance you will really save my butt if you can get me out of this mess!
-Martin
Answer by Mike 3 · May 18, 2010 at 06:41 PM
You'll need a script to work out how much of the normalized screen you want it to take up
example:
private var lastPos : Vector2 = Vector2.zero; var absolouteWidth = 100.0; //in pixels var absolouteHeight = 100.0; var minimapCam : Camera;
function Update() { if (minimapCam == null) return;
var currentPos = Vector2(Screen.width, Screen.height); if ((lastPos - currentPos).magnitude > 2) { lastPos = currentPos;
//you can modify this to put it somewhere else if you like
minimapCam.pixelRect = new Rect(Screen.width - absolouteWidth, Screen.height - absolouteHeight, absolouteWidth, absolouteHeight);
}
}
ok mate this semi works xD i set the H and W to 200 each and it get the size it needs, only problem remains now, that it goes to the buttom of the screen ins$$anonymous$$d of top xD know a way to fix this? ty in advance and for your time
you got a "solved" mate :D thanks alot, just added "Screen.height - absolouteHeight" ins$$anonymous$$d of 0 and it worked thank you SO $$anonymous$$UCH!!
Answer by StephanK · May 18, 2010 at 06:41 PM
Yhe problem is, that the normalized viewport rectangle uses floats to determine its size. These floats are between 0 and 1 and can be read as percentage of the overall screen size. If you want a fixed width of a certain viewport you will have to determine the overall size of the screen (Screen.width, Screen.height) and calculate the factor (between 0 and 1) yourself (factor = fixedWidth / Screen.width) and then tell the viewport to use the calculated size.
Answer by Wraifen_09 · Oct 05, 2018 at 01:28 AM
{
public float absolouteWidth = 100; //in pixels
public float absolouteHeight = 100;
public GameObject Minicam;
void Update()
{
if (Minicam == null) return;
var lastPos = Vector2.zero;
var currentPos = new Vector2 (Screen.width, Screen.height);
if ((lastPos - currentPos).magnitude > 2)
{
lastPos = currentPos;
//you can modify this to put it somewhere else if you like
gameObject.GetComponent<Camera>().pixelRect = new Rect(Screen.width - absolouteWidth, Screen.height - absolouteHeight, absolouteWidth, absolouteHeight);
}
}
the new 2018 way, works a treat