![]() ![]() UseAs : Is a variable of Usage type, so this will tell us basically, how are we going to use this script Usage : Is an enum, with all the possible uses of the button. Really Jojo? All that, clean and is simple to use? It’s a simple script, that requires a collider (2D or 3D) to be attached to a game object, and will let you use that as a button that can open a URL, load a scene, switch GUI panels (or basically hide and show objects), start a coroutine, exit the game, send events, and even use it for IAP purchases, all in one, super clean and easy to use script. The script we will be talking about today as I said before, is SmartButton. I added several stuff I wanted to use (still wanting to add more), later changed the checkbox for an enum, and that’s it! a simple and reusable script, that I’d like to share with you! Alright, how does it work? ![]() So I said to myself, “Jojo, why don’t you use the same script and just add a checkbox to it that let’s you choose what behavior will it have?! ![]() Then, I stumble onto something I did a dozen times. And that is how I created the “ SmartButton“. After doing some scripts that let me show some panel and hide another, I realized, what If I create a simple script, that lets me do just that? I could just use it in every project and with only two game object drags, I would have a full flow in a matter of seconds. It had several menus as usual (main menu, credits, options, store, etc). When I created this script, I was creating a GUI for a game. If the answer is NO, then you should really take at least some minutes to think if it’s easier to do it in some other way that lets you do that! When creating scripts, sometimes my main thought is, if I take this script and just drop it in another, and entirely different project, will it work? And how, if you find some time, making them look better, will also save you time and bugs! Lots of scripts are bad for your health Thinking before coding Hello, I’m Jojo! and in this post of our Unity tutorials series, we’ll see how simple and highly reusable scripts can make your life easier in Unit圓D. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |