I am attempting to create a GUI for a strategy game. There are only a few unit types, but there are often more than one instance of a unit type on screen at the same time, and each instance will have its own set of buttons. I was hoping to create one GUI.Window, and change the information/functionality of the buttons in the window, depending on which unit is selected.
The problem I am having is if there is a clone of a unit in the game, only the original unit will display the GUI.Window on selection. So, I can switch between one soldier, and the Base building, but it will never pull up the GUI.Window for the second soldier.
Will I have to have a separate window ID for each individual unit? Is there another way to do this possibly? Thanks.
var iconA : Texture2D;
var iconB : Texture2D;
var unitName : String;
var buttonA : Rect = Rect (5, 20, 40, 40);
var buttonB : Rect = Rect (50, 20, 40, 40);
var buttonC : Rect = Rect (95, 20, 40, 40);
var buttonD : Rect = Rect (140, 20, 40, 40);
public var _showBaseActionBar = false;
public var _showSoldierActionBar = false;
var ActionBarWindowRect : Rect = Rect (0, Screen.height-60,185,65);
function Start () {
}
function OnGUI () {
var ActionBarWindowRect : Rect = Rect (0, Screen.height-60,185,65);
if (_showBaseActionBar == true) {
unitName = "Base";
ActionBarWindowRect = GUI.Window (0, ActionBarWindowRect, ActionBarBuilding, unitName);
}
if (_showSoldierActionBar == true) {
unitName = "Soldier";
ActionBarWindowRect = GUI.Window (1, ActionBarWindowRect, ActionBarSoldier, unitName);
}
}
function ActionBarBuilding (windowID : int) {
// Draw any Controls inside the window here
if (GUI.Button (buttonA, iconA)) {
// execute button function here
}
if (GUI.Button (buttonB, iconA)) {
// execute button function here
}
if (GUI.Button (buttonC, iconA)) {
// execute button function here
}
if (GUI.Button (buttonD, iconA)) {
// execute button function here
}
}
function ActionBarSoldier (windowID : int) {
// Draw any Controls inside the window here
if (GUI.Button (buttonA, iconB)) {
// execute button function here
}
if (GUI.Button (buttonB, iconB)) {
// execute button function here
}
if (GUI.Button (buttonC, iconB)) {
// execute button function here
}
if (GUI.Button (buttonD, iconB)) {
// execute button function here
}
}