Hey everyone,
I’m trying to make a window with several buttons that appears once a bar has finished filling up over time. I’ve managed to get the bar working fine and the window to appear once the bar is filled and disappear when a button is pressed. The problem is that one of the button’s functions is being difficult to properly construct. It is an ability that will cause the character to regenerate health until the bar is finished filling up again.
here is a bit of the script where I think the problem occurs.
This part takes place inside OnGUI.
// a boolean to turn on/off the abilities window for the timer bar
var tAbilitieswinswitch : boolean = false;
// an if statement to make the abilities window appear.
if (tAbilitieswinswitch == true){
var tAbilitieswin = GUI.Window (1, Rect(110,250, 100, 100), tAbilities, "Abilities");
}
}
function tAbilities (windowID){
// the buttons that appear inside the abilities window and their functions
var taButton = GUI.Button(Rect(5, 25, 50,20), "Attack");
if (taButton == true){
tAttackCommand();
}
var tdButton = GUI.Button(Rect(5, 45, 50,20), "Defend");
if (tdButton == true){
tDefendCommand();
}
}
and later on the tDefendCommand function, which doesn’t want to behave properly…
function tDefendCommand(){
//Function for character to defend once defend ability is used
Debug.Log( "Defend button is defending");
tAbilitieswinswitch = false;
tTimer = 1;
if (tTimer >= 1 tTimer < tSpeed){
tHP += 1 * Time.deltaTime;
}
if (tTimer >= tSpeed){
Debug.Log("Defend button is done defending");
}
tTimer and tSpeed are variables used for the bar that fills over time. That function is called during Update and looks like this…
function tTimerFill(){
// timer bar and ability activation
if (tTimer >= 1 tTimer < tSpeed){
tTimer += 10 * Time.deltaTime;
if (tTimer >= tSpeed){
tAbilitieswinswitch = true;
}
}
}
I have a feeling the problem is related to how Update and OnGUI work based on frames but I’m not sure how to make the tDefendCommand work properly. I’m kinda new to programming so forgive me if I’ve done something horribly wrong.