Hello UnityAnswers- I need help figuring and setting this up. Here is the situation- I would like to set, store/recall creatures with buttons that are automatically assigned to them when I allow them in my party.
I have no idea on how to set this properly, so I'll attempt something we can start on...I know it's lame, but it's all I understand to tackle this yet :(
On Beasts speech
Long story short--
- Creature asks to join your party..
- You say yes/no
-
if you say yes:
do something like ( `Hero.Beast *= gameObject;` ) ???
*
*
On Hero's script
* *```* *static var Beast : GameObject [];* *function OnGUI(){* *var LineupInt : int = -1;* *var LineupStrings : String[] = ["Beast1", "Beast2", "Beast3"];* *LineupInt = GUI.Toolbar (Rect (25, 25, 250, 30), LineupInt, LineupStrings);* *if(LineupInt == 0) // press Button1* *if (Beast.length > 0){* *if(Beast[1] != null)* *Beast[1].SetActiveRecursively(false);* *else if(Beast[1] == null)* *Best[1].SetActiveRecursively(true);* *}* *if(LineupInt == 1) // press Button2* *if (Beast.length > 0){* *if(Beast[2] != null)* *Beast[2].SetActiveRecursively(false);* *else if(Beast[2] == null)* *Best[2].SetActiveRecursively(true);* *}* *etc* *```* *So, how do I tell the Hero's script Beast[] string to assign someone to the next available number, then reference them again specifically with the buttons?
* *Thanks for any help! ( ps- how bad is my attempt too? I'M TRYING! :)
* *EDIT: My answer
* *Okay, here is the set up:
* *in the dialogue script, if you accept the offer to join your team, I said this
* *Hero.Beast.Push (gameObject); to add to the array
* *in the Hero's script I put this
* *```* *static var Beast = new Array();* *var beast1 = false;* *var beast2 = false;* *var beast3 = false;* *var beast4 = false;* *function OnGUI () {* *var LineupInt : int = -1;* *var LineupStrings : String[] = ["Beast1", "Beast2", "Beast3"];* *LineupInt = GUI.Toolbar (Rect (25, 25, 250, 30), LineupInt, LineupStrings);* *// Beast ONE* *if (LineupInt ==0)* *if(Beast[0] != null){* *print(Beast[0]);* _//** The first is set at the start of the level- will edit later **_ *// Beast TWO* *}if(LineupInt ==1)* *if(!beast2)* *if(Beast[1] != null) {* *print("Beast 2 is stored");* *LineupStrings[1].name = Beast[1].name; //(???) see comment* _Beast[1].transform.position = transform.position + transform.right * -4 + transform.up *7;_ *Beast[1].transform.parent = transform;* *Beast[1].SetActiveRecursively(false);* *LineupInt = -1;* *beast2 = true;* *}if(LineupInt ==1)* *if(beast2){* *print("Beast 2 is released");* *Beast[1].SetActiveRecursively(true);* *Beast[1].transform.parent = null;* *LineupInt = -1;* *beast2 = false;* *//And so on and so forth for each button in the toolbar* *```*
Thank you so much Jahroy- I appreciate your above and beyond help. What stuck out the most for me was your mentioning of "Push"; (I couldn't really grasp the rest of your examples at my exp Level yet, but I will be referencing back as my unity exp grows- so your examples wont be wasted!).
– superventureAs for the 'see comment' mentioned above, how on earth do you change the name of a toolbar button? Is it possible? This button method works for me so far, but it sure would nice to know specifically who you call out instead of just clicking Beast1/2/3.
– superventureTry putting your 4 beasts into an array. Then you have some options about how to create dynamic labels for your buttons. My example code shows two different methods. The first one uses the function getBeastNames(). This function loops over the array named beastArray and returns an array of strings that contains the name of each beast. This can be passed to GUI.Toolbar(). The second example uses a for loop to iterate over an array of beasts. It draws a button for each beast and uses its name for the button label. I'll add an answer with some new code, too...
– jahroy