jeudi 9 mars 2017

Why don't my if statements check the values of my function correctly?

So I have code elsewhere that puts a pointer in a position based on the AttackInfo.Target value. I also have code that determines whether my characters are dead, using the Stats[lifeStatus] array reference, where 0 is dead and 1 is alive. I basically want the Target to skip over the values of dead characters, so you can only select living characters to attack. However, it seems to have no effect. Why won't it work?

else if (state == CHARACTER1TARGETCHOICE) {
    attackButton.enabled = false;
    abilitiesButton.enabled = false;
    itemButton.enabled = false;
    defendButton.enabled = false;
    fleeButton.enabled = false;
    if (pointer.GetComponent<SpriteRenderer> ().enabled == false) {
        pointer.GetComponent<SpriteRenderer> ().enabled = true;
    }
    if (Input.GetKeyDown (KeyCode.UpArrow)) {
        character1AttackInfo.Target -= 1;
        bool checkTargetAlive = false;
        while (checkTargetAlive) {
            if (enemy1Stats [lifeStatus] == 0 && character1AttackInfo.Target == 1) {
                character1AttackInfo.Target -= 1;
            } else if (enemy2Stats [lifeStatus] == 0 && character1AttackInfo.Target == 2) {
                character1AttackInfo.Target -= 1;
            } else if (enemy3Stats [lifeStatus] == 0 && character1AttackInfo.Target == 3) {
                character1AttackInfo.Target -= 1;
            } else if (enemy4Stats [lifeStatus] == 0 && character1AttackInfo.Target == 4) {
                character1AttackInfo.Target -= 1;
            } else if (character1AttackInfo.Target == 0) {
                character1AttackInfo.Target = 4;
            } else {
                checkTargetAlive = false;
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire