Hi, Im making board game for 4 players (not online), I created some sort of Dice Roll System but now I am thinking, what would be best solution to make it work with different systems in the future, for example, players use 1 dice for movement, 2 dices for fighting. Enemies want to " roll" dice/dices too in fight scenarious. Do I just create Instance of DiceController class everytime I want something to have and “roll” dices? I would do this but I feel like something is wrong with this solution. Its kinda my first time doing something like it with OOP.
using UnityEngine;
using Random = UnityEngine.Random;
public class DiceController : MonoBehaviour
{
List<Dice> dices = new List<Dice>();
int totalvalue;
private class Dice
{
int numberOfSides = 6;
public int throwDice()
{
return Random.Range(1, numberOfSides + 1);
}
}
public void CreateDices(int numberOfDices)
{
dices.Clear();
for (int i = 0; i < numberOfDices; i++)
{
Dice dice = new Dice();
Debug.Log($"Dice is created, totalDices {dices.Count + 1}");
dices.Add(dice);
}
}
public int throwDices()
{
if (dices.Count == 0)
{
return 0;
}
for (int i = 0; i < dices.Count; i++)
{
totalvalue += dices[i].throwDice();
}
return totalvalue;
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
var value = 0;
CreateDices(4);
value = throwDices();
Debug.Log(value);
}
}
}