GUITexture script

Hi everyone,

Let me first say what a fantastic product!
I’m new to the Unity3D community so please go easy on me.

I’m looking for a simple GUITexture button script to get me started.
Even an Application.LoadLevel will do.

I know thousands of the veteran coders out there are rolling their eyes right now. ; )

A little background:

I’ve been able to get a great start in the main Unity program – getting things to function based on the many great tutorials posted by Unity and the Unity community. Thank you!

Unity iPhone however is another story. (Sound familiar?) Hi Higgy B.!

For starters, I’ve read most of the posts from other Unity iPhone users regarding various issues like getting simple buttons to work, etc. and it’s not all that cut-and-dry for a “Newbie” to comprehend.

I’ve clicked on most of the links provided by users taking you to example code that carries out various actions, etc. Although the code might work great, it usually doesn’t tell me, the “Newbie” enough to make it work. This goes here, that goes there, etc.

With all due respect to the Unity developers:

I know updated documentation is coming. Clearly the iPhone section of the documentation is still in the works (mainly because it’s such a new product.) Understandable.
In the mean time, can something very simple be posted on the Unity website for Unity iPhone newcomers?
They would very much appreciate it. Based on the forums, it’s been requested several times.
It’s a very exciting piece of software, and new users want to be able to hit the ground running, especially after spending $600 only to be frustrated by the lack of iPhone information in the manual.

I’ve downloaded Penelope from the app store. Very cool. I know a tutorial is coming for that project but I have a feeling most of the scripting will be beyond most of the simple scripts the “Unity iPhone newbies” are requesting.

Thanks in advance for any help you can provide.
And thank you to Unity for all their hard work in putting out such a great product.

Best regards,

David

u3dclt (David):

Can you give us a little more information?

Background aside (tx!), what do you need the GUITexture button script to do?

There are many solutions!

Little Angel,

Thanks for your response!

Let’s start simple and we can build from there. I’ve been reading that GUITexture buttons are a more efficient that OnGUI buttons when porting to the iPhone.
There are probably more efficient ways that GUITexture to make a button (to reduce draw calls, etc.) but it would probably be over my head at this point.

This will be for 3D content by the way.

Here we go:

  1. Have a visible button(s) on the screen that when pressed, carries out an action.

• Makes an object move in a particular direction.

• Performs an Application.LoadLevel

• Triggers a prefab

• Triggers an imported animation from a 3d application.
( I can handle the coding on this for the regular unity – based on tutorials – but not Unity iPhone, with touch scripting).

Any help is greatly appreciated! Thank you.

David

First off, don’t abandon OnGUI completely. I’ve found it useful in non-critical areas like the start menu, and end game displays where frame rate are not a big issue.

When it comes to GUI elements in your playing game, you’ll see me advocating this solution here and there…

So far the best solution for buttons on the iPhone I’ve found it SpriteUI.

There is also GUIManager.

Both of these are based on SpriteManager.

You can google or search the forum for any of those keywords. This will help you jump right in and get started with buttons on the iPhone.

I don’t know about GUIManager, but I know SpriteUI has both C# and Unity.js solutions. You can use SpriteUI to make buttons, labels, moving sliders and dials, speedometers and other gauges, etc… You’ll need one instance of the manager for each 1024^2 texture atlas you need.

Give one of them a go, and if you are still having probs, post again here and I’ll check it out.

Little Angel,

Thanks for the info on SpriteManager and SpriteUI.
It looks very promising. I’l have to check it out.

By the way.
I downloaded the “SpriteManager” (zip) file without a problem.

The “SpriteDemoPackage.unityPackage” file wouldn’t download for some reason. Maybe because it’s not zipped. Is there another way to get that?

Sounds like there’s a tutorial coming? Looking forward to that.

Thanks a lot.

The tutorial is coming VERY slowly, as I’m 60% on baby duty, and the rest on trying to get my first iPhone title done. If you have any q’s go ahead and ask me here or in SpriteUI.

When it comes to DL’ing the “SpriteGuiExample_1.5.2.unityPackage” (which can be found HERE), I found that I needed to “force download” the unityPackage by (on the Mac) holding down the key and clicking “download”. I am then given the option to “download linked file” in a pop up window, which I select to download to my computer, otherwise my current browser tries to load it into a new window as text.

If you are interested in SpriteUI, all you need is the “SpriteGuiExample_1.5.2.unityPackage”. It includes all the dependencies it requires.

Hey Little Angel,

Finally getting back to this.

That’s a good sample to get started with in SpriteUI.

I was able to download the files after all. It was a Safari issue.
Firefox downloaded properly.

I know you’re on baby duty but was wondering how your first iPhone app is coming (base on your previous message). I’m interested in seeing what you’re working on.

Now remember. Hold baby with the left hand, code with the right!

Hang in there!

I probably will have SpriteUI related questions the farther along I get.

Thanks!

u3dclt:

My first iPhone app is coming along fine, and I hope (finger’s crossed) to get it to Apple™ by the end of the week. I’m doing beta testing and final polish.

Here’s a sample of what I’ve done with SpriteUI for in-game indicators:

The design for all the indicators is based on rotating the arrow over a static background. Low fuel and collisions cause the grey backgrounds to go yellow and red, as necessary. Collisions ‘blink’ on impact, and fuel ‘flashes’ when in low fuel situations.

On other parts of the screen or other parts of the game are buttons, splash screens and menus.

I find SpriteUI to be very versatile, but, when my sprite count began to reach around 100 individual sprites (… one of those indicators can be created from 5 - 7 separate sprites, so that spread of indicators above requires something like 25 sprites…) I found the load time at the beginning of the scene was taking over a second and nearly two to run through function Start() on MyUIManager alone. So, in the end, I pared down on how much work I actually did in SpriteUI. I limited my SpriteUI load to be only the sprites I needed during actual game play - and all other menus and splash screens (except 2 that I just haven’t had the time to depreciate) were moved back to OnGUI GUI.x. To keep the function OnGUI() from firing, I linked and cached the scripts and toggled them on and off as needed, so it only used up CPU cycles to drive function OnGUI when the game was not actually playing.

Little Angel,

Wow, you’re getting close. Hopefully it goes through Apple quickly and you’re on your way!

Will you post a note and link when it’s ready so we can take a look?
I’m curious if you’re also promoting and marketing it on it’s own website.

Good luck with all the fine tuning.

Finally got a chance to do some testing on SpriteUI and I like the simplicity of how it works.

I am however interested in animating my GUI buttons, etc. in and out of the screen (I would also like to adjust alpha settings later on, but not critical at this point). What do you think is the best way to accomplish this? I know SpriteManager does this, right? Still a little fuzzy on how they work in conjunction with one another.

Because I’m a scripting newbie, whatever is easier for me to comprehend would be best for now.

Thanks a lot !!!

If you read through the SpriteUI thread, you’ll get hints on how to reposition/animate sprites. It may take some experimenting. It can be done. Look at the discussions on Health Bars Radars to get started.

Transparency and alphas? I’ve neither seen any hints nor found a way to change those, but I’ve not really looked. Could be a call for CPD? Dig thru the SpriteUI code? I know I’ll want to use that functionality eventually. Post anything you find in the SpriteUI thread for the others to see.

Actually, it might be worth posting the animate and transparency questions on bat thread in case someone else subscribed to it might have an answer.

Thanks Little Angel!

I’ll continue to scope it out to see what I can find.

At this point it seems like SpriteUI is mainly for static sprites and SpriteManager and Ani.Mate will animate sprites. Or am I missing something?

SpriteManager and its code might be over my head but I’ll see if I can get somewhere with the step-by-step provided in the thread this weekend.

I think I really need some kind of tutorial. I’ll keep digging.

Thanks again.

Certainly SpriteManager is for animating sprites, but afaik, it’s primarily for in-game objects. I believe people have used them for hordes of rats and other high-volume issues rather than GUI objects. That being said, it’s not a thread I follow and I find that it intimidates me! (~.^)

I have no experience with Ani.Mate either.

Let me know what you find out!

I’ll keep digging and keep you posted.

I might just have to take the static GUI route for the first round (boring), and update later on. Don’t really want to settle for that though.

Cheers!

You can apply changes to the “transform” of the sprite over time in SpriteUI.

Currently I only use it to rotate a sprite, rather than relocate it, but I am sure you could do that.

I’d use some form of this code I use to rotate my graphics…

From ShipController.js inside function Update ():

//	Update SpriteUI
myUIManager.UpdateAttitude (transform);

A stand-alone function in MyUIManager:

//	Update Attitude called from ShipController.js
function UpdateAttitude (playerTransform : Transform) {
	var attitudeFGTransform : Transform = attitudeFG.client.transform;
	attitudeFGTransform.rotation = playerTransform.rotation;

	attitudeFG.Transform();
}

This code displays the transform.rotation of the player ship in the upper right of the game:

You could look at the client.transform.position (I’d assume) and use a boolean to trigger code in an Update() to move your sprites…

make sense?

Out of the office until tonight.
I’ll scope the transform client out later on.

As far as it making sense? Yes and no.
I am just migrating to JavaScript and other related languages to this
platform. Have minimal experience with actionscript and Flash.

Have tons of graphic experience. Just trying to bring it to life.
More later.

Thanks for sending!