I found myself in a quite difficult situation. I have a script calling this custom function:
HorButton (SideX,5,25,"HOME",11,1,BackSxTEX,EmptyFillTEX,EmptyDxTEX,gameObject,MENU_MyShoes,MENU_LandingPage);
This function builds a dynamic horizontal button made up of three different parts and textures, with a variable lenght depending of the text lenght. Anyways, I need to pass to this function two different javascripts: one is MENU_MyShoes, wich is the script who's actually calling the HorButton function. The other javascript to pass is MENU_LandingPage, wich is the next menu that will be loaded after pressing the generated button.
And this is the whole function code. The problem is that I absolutely don't know what to insert where I wrote "?????":
public function HorButton ( SideX : float, posX : int, posY : int, Testo : String, Molt : float, Dir : int, TexSX : Texture2D, TexCX : Texture2D, TexDX : Texture2D, obj : GameObject, OldScript : String, NewScript : String ) {
/*Lots of GUI code here*/
if (GUI.Button(Rect((posX/HD)+SideX,posY/HD,(posX+TexSX.width+(Testo.length*Molt)+TexDX.width)/HD,TexCX.height/HD),Testo)){
var NewMenu = gameObject.AddComponent(NewScript) as ?????;
NewMenu.SideX = Screen.width*(-Dir);
NewMenu.fase = "intro";
var OldMenu = obj.GetComponent(OldScript) as ?????;
if (Dir > 0)
OldMenu.fase = "outroDX";
else
OldMenu.fase = "outroSX";
}
}
I literally have no clue on how to solve this, since I always end getting that "X is not member of Y" error... I don't know how to cache these two scripts. Keep in mind that this function must be reusable from a lot of different scripts, so the variables
NewScript and
OldScript must be able to read every Javascript I pass to them...
Thanks for everyone who can help!
asked
May 07 '12 at 04:02 PM
DanjelRicci
380
●
17
●
20
●
31
To clarify: you want to call an arbitrary function from another function, and pass the name of that function via the parameters? Where does that other function live, and is static/globally accessible? Why are you trying to add the script to the gameObject's component list in the first place?
I'm trying to do the exact same thing - pass a script name into a function by can't figure out what type to declare the variable "OldScript" or "NewScript". I started out with trying type "String" as well and got the same "not a member of" errors. Did you ever solve this? I would love to know!