I've been trying to set up a battle system using Unity but I've hit a bit of a snag: Player Turn script
static var Playerturn: boolean = true;
function Awake(){
Select();
}
function Select(){
print("Make your move!!");
yield WaitForSeconds(2);
Battle_Menu.choice = true;
print("Battle Phase Begins!!");
yield WaitForSeconds(2);
//BattlePhase();
}
static function BattlePhase(){
//RPGPlayer.OnAttack();
RPGEnemy.OnDamage();
yield WaitForSeconds(2);
print("Battle Phase Ends!!");
TurnEnd();
}
static function TurnEnd(){
print("Turn end!");
if(Playerturn == true){
Playerturn = false;
Enemy_Turn.Select();
}
if(Playerturn == false){
Playerturn = true;
}
}
function GameOver(){
//Play audio oneshot
//Destroy player
//WaitforSeconds();
//Load level GameOver
}
function Victory(){
//Play audio oneshot
//Destroy enemy
//WaitforSeconds();
//Load level Victory
}
Menu Script:
static var choice: boolean = false;
function OnGUI () {
if (choice == true){
// Make a background box
GUI.Box (Rect (10,10,100,90), "Battle Menu");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Attack")) {
//Application.LoadLevel (1);
RPGPlayer.OnAttack();
print("The Player Attacks!!");
Run();
choice = false;
}
// Make the second button.
if (GUI.Button (Rect (20,70,80,20), "Defend")) {
//Application.LoadLevel (2);
RPGPlayer.OnDefense();
print("The Player blocked!!");
Run();
choice = false;
}
}
if (choice == false){
return;
}
}
function Run(){
Player_Turn.BattlePhase();
}
Basically, I tried to run it to where the player turns begins and displays an attack or defend button using OnGUI and it sends makes the Player Turn function Battle phase run. However, the code stops progressing once the player chooses attack or defend and it stays put.
Does anyone have a solution?
Edit: Thanks to all the gave an answer. This will greatly benefit the Unity community!