- Home /
Button managment best practices
Hello, I am looking to get some advice from someone more experienced in game programming. I am currently working on an android project that will rely heavily on the users touch on many different buttons (menus, options, settings, selections ect.)
As for managing these buttons functionality is it best practice to write an individual script for each button so that they are independent from eachother or to write a general 'button script' that sends information to a 'button controller'?
For example, I currently am using the latter method with NGUI. I have a generic button script that goes on all of the button objects to detect when a touch occurs. When touched the script uses a 'SendMessage' function to send what object was touched to a button controller script. Example scripts below...
The script on SampleButton:
//Button.js that goes on every button in game
var buttonController: ButtonController; //the buttonController.js
/*
* called on release of a button.
*
* tells buttonController.js to process the function with the same name as this button
*/
function OnClick()
{
buttonController.SendMessage(gameObject.name);
}
The ButtonController script
//variables go here
function SampleButton()
{
DoStuff();
}
My question: Is it practical to go about handling button interactions in this manor? If not, what are some of the more commonly used methods that would be practical and efficient?
Thanks in advance,
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Enemy Select 1 Answer
How can i make this in c#,How can i make this switch bar? 0 Answers
Reset button 1 Answer