I just discovered that nested functions do not work due to Unity’s architecture. so is there anyway to achieve essentially the same thing by calling an entire script full of functions within the function in another script? what would that code like in JS?
Thanks in advance.
if they have similar parameter signature then you could go about using delegate or anonymous methods.
void A()
{
Debug.Log("A");
}
void B()
{
Debug.Log("B");
}
delegate void DelegateController();
DelegateController d = ()=>{A (); B ();};
d.Invoke(); // <- this is what executes both functions
Output:
A
B
So here are the various functions that I want to reduce to one “MechName” function called Shadowcat. that way when I click something to invoke the Shadowcat function in a GUI setting of the loadout screen, all the data for that Mech is called forth from Voodoo Child.
function ShadowcatCenterTorso ()
{
BackstageTonnage.Hardpoint = 1;
BackstageAmmo.Laser = true;
BackstageArmor.Armor = 30;
}
function ShadowcatRightTorso ()
{
BackstageTonnage.Hardpoint = 2;
BackstageAmmo.Missile = true;
BackstageArmor.Armor = 20;
}
function ShadowcatLeftTorso ()
{
BackstageTonnage.Hardpoint = 2;
BackstageAmmo.Missile = true;
BackstageArmor.Armor = 20;
}
function ShadowcatRightArm ()
{
BackstageTonnage.Hardpoint = 2;
BackstageAmmo.Laser = true;
BackstageArmor.Armor = 10;
}
function ShadowcatLeftArm ()
{
BackstageTonnage.Hardpoint = 2;
BackstageAmmo.Ballistic = true;
BackstageArmor.Armor = 10;
}
function ShadowcatRightLeg ()
{
BackstageArmor.Armor = 10;
}
function ShadowcatLeftLeg ()
{
BackstageArmor.Armor = 10;
}