- Home /
GUI.Lable slowdown problem
Hi guys, I'm trying to make an inventory menu where behind the object there is their respective names, this is the code I used in the OnGui() function:
if(iMode)
{
//Mostra i nomi degli oggetti
var div = gridPosition * 2;
if(div < currentInventoryObjects.length)
GUI.Label(Rect(startPos+100,startPos+25,iconSize+100,90), currentInventoryObjects[div].name + ".obj", customGUIStyle2);
if(div +1 < currentInventoryObjects.length)
GUI.Label(Rect(startPos+100,startPos+iconSize+60,iconSize+100,90), currentInventoryObjects[div+1].name + ".obj", customGUIStyle2);
if(div +2< currentInventoryObjects.length)
GUI.Label(Rect(startPos+iconSize+185,startPos+25,iconSize+100,90), currentInventoryObjects[div+2].name + ".obj", customGUIStyle2);
if(div+3 < currentInventoryObjects.length)
GUI.Label(Rect(startPos+iconSize+185,startPos+iconSize+60,iconSize+100,90), currentInventoryObjects[div+3].name + ".obj", customGUIStyle2);
if(div+4 < currentInventoryObjects.length)
GUI.Label(Rect(startPos+2*iconSize+255,startPos+25,iconSize+100,90), currentInventoryObjects[div+4].name + ".obj", customGUIStyle2);
if(div+5 < currentInventoryObjects.length)
GUI.Label(Rect(startPos+2*iconSize+255,startPos+iconSize+60,iconSize+100,90), currentInventoryObjects[div+5].name + ".obj", customGUIStyle2);
}
What is wrong with this code is that it drastically slows down the frame rate for some reasons. I'm still learning and I don't really use GUI that much, is there any other way to do this?
I don't see anything particularly expensive here, just * and +. Strange. What platform are you working with ? Even mobile that shouldn't be a problem. You're sure the problem comes from that code ?
Agreed, that code wouldn't cause any noticeable slowdown by itself.
I'm working on PC, If I delete that part the game act like normal, what could it be?
I can't believe it! Today it's just working fine! Well, I suppose that sometimes turning off the pc really helps o-o
Your answer
![](https://koobas.hobune.stream/wayback/20220613064241im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUILabel doesn't show up 1 Answer
Score display not working 1 Answer
How to change how meany decimals are in a GUI sound slider 2 Answers
Randomize GUI Position 2 Answers
Gui label and gui button 1 Answer