GUITexture button

Hi there

My main level requires 4 buttons on the screen…
My timer and score shows their values as custom drawn images…
Combined with the other textures on screen this gives me a total of 23 DrawTexture() calls.

I read somewhere that the GUI system is not optimized for the iPhone and should be avoided wherever possible but if absolutely needed, it should be limited to 2 or three instances.

I thought placing 23 calls in 1 OnGUI function meant it would be 1 instance but it seems 23 calls in 1 OnGUI counts as 23 instances… Ouch!

Now, during a recent support session here on the forum and some debugging, I found that my main menu crashes the iphone because i have 1 OnGUI call that makes 8 DrawTexture calls…

I am now actively trying to change those 23 textures to Gui textures but i have hit a snag…

Most of them can be converted without too much of a pain, but the progress indicators overlay a colored image on top of a single colored version of the same image. As far as I can see, GUITexture cannot clip images so this means my progress indicators will HAVE to be drawn using OnGUI so that is 3 instances already and maxes out my available OnGUI calls… but what about my 4 buttons? That is how the player selects what weapon to use. The way the game works, it is critical for the player to able to change their weapons as quickly as humanly possible so I have simply placed each of the 4 weapons on screen as a button so “tap and use”… Can’t get any faster than that!

Buttons… OnGUI… No more OnGUI calls left… Hmmm… [thinking]… hmmm…
GUITexture… GUITexture as a button???
This brings to mind the following question:
“How did people impliment on-screen buttons BEFORE the new GUI system?”

Can one use a GUITexture as a button?

I saw on the occlusion sample project that they test wether a player has hit a button by testing the screen coordinates of the touch.Is that the only (optimized) way to implement buttons on the iPhone?

well, you could still parent single textured polygons with transparrent diffuse shader to the camera and check collision on it, but testing mouse coordinates on gui textures should be the better way, if your gui elements are never moving.

have you tried setting:

function Awake() {
  useGUILayout=false;
}

with your current code? this should speed up gui quite a bit on iphone, but a few gui things wont work anymore (e.g. windows)

edit

just read your other post, i do use a keyboard made out of gui buttons and useGUILayout=false and it works fine

well that is a bit of good news! Thank you ever so much…

I will most definitely give that a go, then!

Yes you can use GUITextures as buttons and is working well for me.
Use function OnMouseUp() in a script attached to the GUITexture to have reactions on touches.
check this thread:
http://forum.unity3d.com/viewtopic.php?t=16373&highlight=onmouseup
HOpe it helps and bye!

CHEERS, MATE

i actually found that thread of yours a little later on and was very happy to do so :slight_smile: