OnGui() to custom gui

Hello, Unity Community, I have a problem with OnGUI() function. This simple script takes up to .5 ms to update on my Core 2 Duo MacBook Pro. I’m going to port this game to iPhone, and I think that OnGUI() will slow down my game a lot. Is there any way to make this code cleaner or make custom gui to display it?

class Part{
	var name : String;
	var image : Texture2D;
}
var objects : Part[] = [new Part()];
var disabledList : Array = new Array();
private var scrollPosition : Vector2;
function OnGUI () {
	scrollPosition = GUI.BeginScrollView(Rect(0,0,objects[0].image.width + 30,Screen.height),scrollPosition,Rect(0,0,objects[0].image.width + 12,objects.Length *(objects[1].image.height + 10)));
	GUILayout.BeginVertical();
	var obj : Part;
	var inst : GameObject;
	var i : int = 0;
	var able : boolean = true;
	var ii : int = 0;
	for(obj in objects){
		for(ii in disabledList){
			if(ii == i)
				able = false;
		}
		if(able){
			if(GUILayout.Button(obj.image)){
				inst = Instantiate(Resources.Load(obj.name),Camera.main.ScreenToWorldPoint(Vector3(Screen.width /2, Screen.height /2,10)),Quaternion.identity);
				disabledList.Add(i);
			}
		}
		able = true;
		i++;
	}
	GUILayout.EndVertical();
	GUI.EndScrollView();
}

A bit about the code: all images are 64px wide and 64px tall. I’ve mixed GUILayout and GUI because I had never played with GUILayout, it looked more simple for me to mix both.

Is that all of the script? I tried it, and it gives me an error that says that there is no enabled list variable. or are you coding in something other than JavaScript?

Sorry for that, I was coding not in english, and when changed variable names to be a bit english, made a spelling error. It’s corrected rigth now.

what is the script supposed to do?

If you click the button with an image, it should instantiate an object from Resources folder based on it’s name which is set up in inspector and held in Part class

and you problem is you think it take too long to compute?

yes, I’m using a lots of physics, but physics takes only 0.03 ms…

I think it looks fine, if it works for you (I didnt get it to work) I think it would work fine. it seems like you have the right stuff, in the right amounts, and not anything extra

Thanks for your help, JM Studios, I’ve just rewritten my GUI system to use planes and it’s more than twice faster than this script.

ok!! Great for you!!