I’m building my gui controls separate to my game logic controls because I’ll be doing a lot of scenes, so I plan to send the touch information off to the gamelogic script…
My question is this…
I have guiHandler, which is where all touches are handles, and I wish to cache gameLogic (a script) as a variable, however, there might be 50 versions of this scene and each time the guiHandler will be identical but the gameLogic will have a different name, for instance, gameLogic_A, gameLogic_CharlieSheen, etc
I of course thought i could simply try…
var gameLogic : Component;
var scriptName = "RoflCopter";
function Start()
{
gameLogic = GetComponent(scriptName);
}
However the rules of dynamic typing on iPhone make this not work, among other things…
One Idea would be to create an Interface that all your gamelogic classes have to implement.
Probably makes sense anyway to do that. That way you could have your start function look for a suitable object thru
FindObjectsOfType(typeof(IgameLogic));
OR, also via an Interface, you could have the gamelogic class implement a registerMe call to your gui on Awake. Basically reversing the caller/callee logic you sketched in your code.
I see you are using javascript, hopefully Interfaces are supported there as well.
Well, this sounds good, except the GUI for this game needs to be instantly changeable across many scenes, so it makes sense that it parses all the touch data and then feeds it down. In other words, it will need to go GuiScript → GameLogcScript, gameLogic → GuiScript won’t work, so far as I can see it.
Using ‘sendmessage’ etc simply isn’t acceptable either. It seems odd to me that such an important idea (being able to talk between scripts of arbitrary naming) isn’t simple… Have I missed something glaringly obvious here?