I feel I should be able to create references to functions in unity javascript. I’ve done in other languages.
What I’m trying to do is call a particular function based on a certain case. Rather than repeating the call in each case, I’m trying to follow OOP and just set a reference and call my code at the end of my case checking.
Here is the code:
function onGUI()
{
var windowCreateFunction; /* reference to desired function */
switch( activeID )
{
case SCR_TITLE:
windowCreateFunction = CreateTitleScreen;
break;
case SCR_SCORES:
windowCreateFunction = CreateScoresScreen;
break;
case SCR_SELECTRACE:
windowCreateFunction = CreateRaceScreen;
break;
case SCR_HOWTO:
windowCreateFunction = CreateHowToScreen;
break;
default:
windowCreateFunction = CreateTitleScreen;
break;
}
windowRect = GUI.Window ( activeID, windowRect, windowCreateFunction, "How To Play" );
}
function CreateTitleScreen()
{
// setup code
}
function CreateHowToScreen()
{
// some more code stuff
}
etc....
Error occurs at runtime “Cannot cast from source type to destination type.” I’ve tried type setting my var windowCreateFunction and that hasn’t made my script happy either.
thx
-s