combat works until you win or lose then it hangs. I have tried a lot but I don’t have any experience with code, so I will miss obvious mistakes.
so when it’s the players team to attack this script choose pretty much everything. and after that
void ChooseAction()
{
HandleTurns myAttack = new HandleTurns();
//attackers name
myAttack.Attacker = hero.theName;
//type hero or enemy, enemy has its own script
myAttack.Type = "Hero";
//the gameObject that is going to attack
myAttack.AttackersGameObject = this.gameObject;
//the gameObject that will be attacked, chosen randomly
myAttack.AttackedTarget = BSM.enemiesInBattle[Random.Range(0, BSM.enemiesInBattle.Count)];
//the next two lines choose a random attack from the available attacks.
int num = Random.Range(0, hero.attacks.Count);
myAttack.ChosenAttack = hero.attacks[num];
Debug.Log(this.gameObject.name + " has chosen " + myAttack.ChosenAttack.attackName + " and does" + myAttack.ChosenAttack.attackDamage + " damage");
BSM.EnemyTurn(myAttack);
}
so when the last enemy dies it is grayed out like it should be, but the players heroes still choose an attack and everything gets stuck in CheckAlive
void update(){
case (TurnState.Dead):
if (!alive)
{
return;
}
else
{
//change enemy tag
this.gameObject.tag = "DeadEnemy";
//not attackable
BSM.enemiesInBattle.Remove(this.gameObject);
//disable selector
//Selector.SetActive(false);
//get expWorth
exp = enemy.expWorth;
//passing the int, exp to another script called LevelSystem to the function GainedExp(int)
GameObject.FindWithTag("Hero").GetComponent<LevelSystem>().GainedExp(exp);
//remove all enemy inputs
if (BSM.enemiesInBattle.Count > 0)
{
//this removes the dead enemy from the list of upcoming performers
for (int i = 0; i < BSM.nextTurn.Count; i++)
{
if (i != 0)
{
//if the dead enemy already is on the list of attackers we remove it
if (BSM.nextTurn*.AttackersGameObject == this.gameObject)*
{
BSM.nextTurn.Remove(BSM.nextTurn*);*
}
//else if the dead enemy is going to be attacked we find another target at random
else if (BSM.nextTurn*.AttackedTarget == this.gameObject)*
{
BSM.nextTurn*.AttackedTarget = BSM.enemiesInBattle[Random.Range(0, BSM.enemiesInBattle.Count)];*
}
}
}
}
}
//change the color to gray
this.gameObject.GetComponent().material.color = new Color32(105, 105, 105, 255);
//check alive
BSM.heroStates = BattleStateMachine.Actions.CheckAlive;
//set alive to false
alive = false;
//reset enemybuttons
//BSM.EnemyButtons();
break;
}
so if I go to the inspector and change the gamestate to won or lost instead of CheckAlive it puts you back in the gameworld just fine and you can keep going.
case (Actions.CheckAlive):
if (heroesInBattle.Count < 1)
{
heroStates = Actions.Lost;
Debug.Log(“Passed, heroStates = Actions.Lost;”);
}
else if (enemiesInBattle.Count < 1)
{
heroStates = Actions.Won;
Debug.Log(“Passed, heroStates = Actions.Won;”);
}
break;
case (Actions.Lost):
{
Debug.Log(“You have lost the battle”);
}
break;
case (Actions.Won):
{
Debug.Log(“You have won the battle”);
for (int i = 0; i < heroesInBattle.Count; i++)
{
heroesInBattle*.GetComponent().CurrentState = HeroStateMachine.TurnState.Idle;*
}
GameManager.instance.LoadSceneAfterBattle();
GameManager.instance.gameStates = GameManager.GameStates.World;
GameManager.instance.enemiesToBattle.Clear();
}
break;