- Home /
Objects to fit on the screen
Hello guys/girls I need a little bit of help here.
I had placed on the top of the screen some items that you can found them on the ground like weapons etc.
The problem is that when they are less or equal to 3 they can fit on the screen, but if they are more than 3 they just go trough borders.
Here is an example to be more clear
I need a way to scale them down or to scale them just a little bit and to put on two rows.
Any help will be appreciated.
Here is my code to instantiate them
public void CreateItems(float i, int numberOfObjects, float iterator, float offsetX, float yPosition, GameObject itemPrefab)
{
numberOfObjects = objectScript.ItemsNumber;
string letter = objectScript.ItemsColor;
GameObject cube = null;
switch(letter)
{
case "B":
cube = Item_bbg;
break;
case "G":
cube = Item_gbg;
break;
case "O":
cube = Item_obg;
break;
case "P":
cube = Item_pbg;
break;
case "R":
cube = Item_rbg;
break;
case "Y":
cube = Item_ybg;
break;
default: break;
}
//impar
if(numberOfObjects % 2 != 0)
{
iterator = -numberOfObjects +1;
offsetX = 2f;
for(i = iterator; i < numberOfObjects ; i += offsetX)
{
GameObject clone = Instantiate (cube, new Vector3 (i , yPosition, -1), Quaternion.identity) as GameObject;
prefabs.Add(clone);
}
}
//par
else
{
iterator = - numberOfObjects +1;
offsetX = 2.0f;
if(numberOfObjects !=0 )
{
for(i = iterator; i < numberOfObjects ; i += offsetX)
{
GameObject clone = Instantiate (cube, new Vector3 (i , yPosition, -1), Quaternion.identity) as GameObject;
prefabs.Add(clone);
}
}
}
// Check for exceptions case
if(numberOfObjects == 0)
{
return;
}
}
Hi,
You want to make an inventory ? Personnaly i do it with a GUI.Window :
void OnGUI()
{
windowRect = GUI.Window(0, windowRect, Do$$anonymous$$yWindow, " Window");
}
void Do$$anonymous$$yWindow(int windowID)
{
// Item Container
}
The windowRect is the inventory and the object of DomyWindow never go out of the main window ( windowRect ).
I'm a beginner, i hope it will help....
Answer by Exbow · Jul 16, 2014 at 05:45 PM
if you are using an orthographic camera i would suggest you to create a script in which you technically calculate the width of the screen like that
left = Camera.main.ScreenToWorldPoint(new Vector3(0,"put any height you want", Camera.main.transform.position.z));
right = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,"same height here", Camera.main.transform.position.z));
List<itemsIwannaInclude> myItems = new List<itemsIwannaInclude>();
step =(Mathf.Abs(left.x) + Mathf.Abs(right.x)/ (myItems.Count);
float ourScale = ((step * myItems.Count) / (tile.renderer.bounds.size.x * myItems.Count));
for(int i = 0; i < myItems.Count; i ++)
{
myItems[i].transform.localScale = new Vector3(ourScale ,ourScale ,"whatever value");
}
hope that helps.
that's not right.
Imagine you will have an ScreenWidth of 1000 and 10 Items
The ourItemSize will be 100. And if you scale all of the Items by 100 on both axes than will just blow up .
Answer by Radu001 · Jul 17, 2014 at 07:30 AM
Set the position of the first 3 on the screene, and if you have more you can just slide to view others,using NGUI or something write by you.Scaling is not a good idea.
Your answer
Follow this Question
Related Questions
Values are changing but the scale of sprite no. 1 Answer
A node in a childnode? 1 Answer
GUI texture to fit the screen at any resolution? 4 Answers
How to get the screen position in an unlit shader. 1 Answer
Scaling a menu bar 1 Answer