Home>
public class BattleCaracter: MonoBehaviour
{
    const int D1 = 2;// Constant 1
    const int D2 = 4;// Constant 2
    const int H = 2;// complement
*
// Attack method
    public static int Attack (int AT, int R_HP, int R_DF) // Tentative
    {
        int Ans;
        Ans = R_HP-(AT * D1-R_DF * D2) * H;
        return Ans;
    }
}
public class BattleSequence: MonoBehaviour
{
    const int PM = 4;// Number of players
    int cmd = 0;// Command variable
    bool selectcmd = true;// Command selection flag
    // Start is called before the first frame update
    void Start ()
    {
        cmd = 0;
        selectcmd = true;

    }
    // Update is called once per frame
    void Update ()
    {
        if (selectcmd == true)
        {
            if (Input.GetKey (KeyCode.DownArrow))
            {
                cmd + = 1;
                if (cmd>= 5)
                {
                    cmd = 0;
                }
                print (cmd);
            }
            if (Input.GetKey (KeyCode.UpArrow))
            {
                cmd-= 1;
                if (cmd<= 0)
                {
                    cmd = 5;
                }
                print (cmd);
            }
            if (Input.GetKey (KeyCode.Return))
            {selectcmd = false;
            }
        }
        else
        {
            // order of action
            if (MoveController.Player [0] .SPEED>= MoveController.Teki [0] .SPEED)
            {
                switch (cmd)
                {
                    // When attack is selected
                    case 1:
                        MoveController.Teki [0] .HP = BattleCaracter.Attack (MoveController.Player [0] .ATTACK, MoveController.Teki [0] .HP, MoveController.Teki [0] .DEFENCE);
                        MoveController.Player [0] .HP = BattleCaracter.Attack (MoveController.Teki [0] .ATTACK, MoveController.Player [0] .HP, MoveController.Player [0] .DEFENCE);
                        print (MoveController.Player [0] .HP);
                        print (MoveController.Teki [0] .HP);
                        break;
                    // When magic is selected
                    case 2:
                        break;
                    // When you select a special skill
                    case 3:
                        break;
                    // When you choose to escape
                    case 4:
                        break;
                    // When you choose defense
                    case 5:
                        break;
                    // When selecting an item
                    case 6:
                        break;
                }
            }
            else
            {
                switch (cmd)
                {
                    // When attack is selected
                    case 1:
                        MoveController.Player [0] .HP = BattleCaracter.Attack (MoveController.Teki [0] .ATTACK, MoveController.Player [0] .HP, MoveController.Player [0] .DEFENCE);
                        MoveController.Teki [0] .HP = BattleCaracter.Attack (MoveController.Player [0] .ATTACK, MoveController.Teki [0] .HP, MoveController.Teki [0] .DEFENCE);
                        print (MoveController.Teki [0] .HP);
                        print (MoveController.Player [0] .HP);
                        break;
                    // When magic is selected
                    case 2:
                        break;
                    // When you select a special skill
                    case 3:
                        break;}
            }
        }
    }
}
public abstract class Status
{
    public string Name {get;protected set;} // name
    public int HP {get;set;} // Health
    public int Max_HP {get;protected set;} // Maximum health
    public int MP {get;set;} // Magic points
    public int Max_MP {get;protected set;} // Maximum magic point
    public int ATTACK {get;protected set;} // Attack
    public int DEFENCE {get;protected set;} // Defense
    public int SPIRIT {get;protected set;} // Mental power
    public int SPEED {get;protected set;} // Quickness

}
public class Chara: Status
{
    // Konsaku Rakuta
    public Chara (string name, int hp, int mp, int at, int df, int sp, int spd)
    {
        Name = name;
        HP = hp;
        Max_HP = HP;
        MP = mp;
        Max_MP = MP;
        ATTACK = at;
        DEFENCE = df;
        SPIRIT = sp;
        SPEED = spd;
    }
}
Another class {
//instance
        Player [0] = new Chara ("******", 100, 15, 15, 15, 10, 5);
        Player [1] = new Chara ("******", 120, 20, 15, 10, 20, 10);
        Player [2] = new Chara ("******", 100, 10, 10, 10, 10, 15);
        Player [3] = new Chara ("******", 90, 30, 0, 5, 30, 5);
        for (int i = 0;i<4;i ++) {
            Teki [i] = new Chara ("coming", 10, 4, 1, 1, 10, 5);
        }
}

Now we are making a command battle type (turn-based) RPG in Unity.
So I didn't know how to make an attack method.
I don't know how to enter the enemy status without any arguments.
Currently, we have arguments for each enemy, but RPG has a large number of enemies, so if you put each of them in the argument, the code will become longer, so I did not know how to write it.
Also, the character status setting method will work with what is written, but I would appreciate it if you could tell me if this is better or if you have a recommended reference book.
If I want other information, add it.

  • Answer # 1

    It is common to have such a large amount of data in an external file
    It's easy to input in Excel, export it as a csv file, and import it. You might want to make a dedicated tool to adjust the enemy's status.

    If you don't have technical skills, using access etc. will make management easier.