Question Attack values in game not working as intended


New member
Sep 11, 2017
Programming Experience
sorry in advance for not knowing the community. im new at this in so many ways.

i created a dice rolling game in c# and unity and everything is working fine except for when player 2 attacks player 1 the attack value is not what it should be. and i think it is in this bit of code. but 2 hours of fooling with it has yielded no new knowledge. any help would be greatly appreciated. if more code is required kindly ask

[COLOR=#0000FF][FONT=Consolas]if[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] (PhaseName == [/FONT][/COLOR][COLOR=#800080][FONT=Consolas]"[/FONT][/COLOR][COLOR=#800080][FONT=Consolas]Player1AttackGet"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] || PhaseName == [/FONT][/COLOR][COLOR=#800080][FONT=Consolas]"[/FONT][/COLOR][COLOR=#800080][FONT=Consolas]Player2AttackGet"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas])[/FONT][/COLOR]
            DiceS1 = Random.Range([COLOR=#000080]1[/COLOR], [COLOR=#000080]7[/COLOR]);
            DiceS2 = Random.Range([COLOR=#000080]1[/COLOR], [COLOR=#000080]7[/COLOR]);
            [COLOR=#0000FF]if[/COLOR] (PhaseName == [COLOR=#800080]"[/COLOR][COLOR=#800080]Player1AttackGet"[/COLOR]) {
                Player1ATK = DiceS1 + DiceS2;
                Player1ATK = Player1ATK - Player2AddedDEF;
                CombatP1On = [COLOR=#0000FF]true[/COLOR];
            [COLOR=#0000FF]if[/COLOR] (PhaseName == [COLOR=#800080]"[/COLOR][COLOR=#800080]Player2AttackGet"[/COLOR]) 
                Player2ATK = DiceS1 + DiceS2;
                Player2ATK = Player2ATK - Player2AddedDEF;
                CombatP2On = [COLOR=#0000FF]true[/COLOR];
        RollDiceButton.interactable = [COLOR=#0000FF]false[/COLOR];
        NextPhaseButton.interactable = [COLOR=#0000FF]true[/COLOR]; [COLOR=#000000][FONT=Consolas]    }
You've simply dumped your code without explaining to us what it's actually supposed to be doing, so it's rather hard for us to determine why it's not doing it. That said, this looks rather suspicious to me:
if (PhaseName == "Player1AttackGet" || PhaseName == "Player2AttackGet")
            DiceS1 = Random.Range(1, 7);
            DiceS2 = Random.Range(1, 7);
            if (PhaseName == "Player1AttackGet") {
                Player1ATK = DiceS1 + DiceS2;
                Player[B][U][COLOR="#0000FF"]1[/COLOR][/U][/B]ATK = Player[B][U][COLOR="#0000FF"]1[/COLOR][/U][/B]ATK - Player[B][U][COLOR="#FF0000"]2[/COLOR][/U][/B]AddedDEF;
                CombatP1On = true;
            if (PhaseName == "Player2AttackGet") 
                Player2ATK = DiceS1 + DiceS2;
                Player[B][U][COLOR="#FF0000"]2[/COLOR][/U][/B]ATK = Player[B][U][COLOR="#FF0000"]2[/COLOR][/U][/B]ATK - Player[B][U][COLOR="#FF0000"]2[/COLOR][/U][/B]AddedDEF;
                CombatP2On = true;
        RollDiceButton.interactable = false;
        NextPhaseButton.interactable = true;     }
I suspect that one or the other of those two lines should be using Player1AddedDEF.
[FONT=&quot]hey sorry i did change that and it did not fix my problem. after getting a little carried away on that script i reverted to original and forgot to change that obvious mistake before i asked my question here. [/FONT]
Top Bottom