- Home /
What data structure to choose how to design the following pattern?
Hello.
I make a small RPG and I have classes for each player (eg. Warrior, Paladin, Wizard). each class can do different things (eg. Attack, Defend, Cast-Spell). The attack and defend of the warrior is different from the wizard as he can swing with his sword and the wizard with his staff.
currently that's what I've done, this code will show a random player option to choose from, but it lacks the class (wizard,warrior..) capability which I want.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using System.Linq;
public class PlayerChoices : MonoBehaviour
{
public GameObject buttonPrefab;
private GameObject panel;
private List<string> playerChoices = new List<string>()
{
"Attack", "Defend", "Cast-Spell", "Run", "Charm", "Use-Item"
};
private List<GameObject> buttons = new List<GameObject>();
private void Start()
{
panel = GameObject.Find("PlayerChoicesPanel");
}
public void ShowPlayerChoices()
{
buttons.ForEach(btn => Destroy(btn));
buttons.Clear();
int numOfChoices = Random.Range(1, 5);
List<string> playerChoicesToShow = playerChoices.ToList();
for(int i = 0; i < numOfChoices; i++)
{
string choice = playerChoicesToShow[Random.Range(0, playerChoicesToShow.Count)];
playerChoicesToShow.Remove(choice);
GameObject button = Instantiate(buttonPrefab, panel.transform);
button.GetComponentInChildren<Text>().text = choice;
buttons.Add(button);
}
}
}
Answer by Larry-Dietz · Nov 29, 2019 at 03:22 AM
This tutorial is a bit dated, but it is a good place to start if you are relatively new, and want to try to start an RPG.
Again, it is dated, but it will teach you a lot... This is the first video of a 200 video series, so be patient :)
Hope you find it helpfull.