- Home /
performance query
im thinking using updates or fixed updates can be juicy if theres a lot of stuff in them as these are checked however many times a second,
so say for instance i have a button that accelerates a bike, runs a sound, an animation, and some other stuff, would it be more effective to have one script in an empty object that basically updates checking if i have pressed a button and when i do a script inside that activates all the other components linked to this button.
or would this cause maybe delay from me hitting the button, enable'ing the other script and then runnning it..
or maybe it would be better to have the script with the update fuction only checking to see if i hit the button and then if i do it runs another function in the script which is my acceleration and so on..
can i have your views on this as i would like to get a head start on saving performance in the long run when more effects, sounds,scripts,objects and so on are added to my overall game.
bare in mind that i am creating my game for the iphone and would like it if possible to be able to run on older gen phones without lag, if not i could always make a less visual effects version for them... i would also like to go onto android but thats another £300 and the phones vary so much i aint guna get into it for a while.
Answer by jahroy · Jan 19, 2012 at 01:15 AM
If you're going to use Unity GUI to draw your button (which makes perfect sense) you will draw the button every frame (which is fine).
If the button is pressed, you will call a function (or functions).
These functions will only get called during the frame the button is pressed.
What they do after that is up to you.
They might change the value of a variable, begin an animation, or play a sound.
They might even change the value of a variable that causes something to happen every frame for a little while.
yh but say im using update would it be better to only check every frame if i push a button as im using touch it has to be update, and then if i do push this butten or gui then enable a seperate function with all the code in it
Touch input works fine with Unity's GUI system.
When you draw a button with GUI.Button(), it detects touch input the same as mouse input.
If you're going to use Unity's GUI system, you have to use OnGUI. That's the only place where you can use the GUI functions. The OnGUI function actually gets called multiple times per frame, but that's O$$anonymous$$. That's how games work. There's no need to be worried about that as a performance hit (yet).
If you want to use Update (only once per frame) you will have to use GameObjects, GUITextures, and things like that.
I use Unity's GUI system (and OnGUI) for all my buttons, sliders, menus, etc... I have never done it the other way.
Your answer
Follow this Question
Related Questions
Advice about overdraw 1 Answer
Best way to create/design modular Player 2 Answers
Halo effect perfomance on mobile devices 1 Answer
Instantiate objects on iPhone affecting performance, strategy. 1 Answer
iPhone 4 game lags 2 Answers