Character selection process
The code provided isn't tested, just used to show an example of what I want to achieve. My mobile game will have a multi-classing aspect and I am just wondering around the best way to select and assign these classes?
public class CharacterClass
{
//Class specific variables here
}
public class PlayerData
{
public CharacterClass primary;
public CharacterClass secondary;
}
public class CreateNewCharacter : MonoBehaviour
{
public void Create ()
{
PlayerData newPlayer = new PlayerData ();
//Best way to assign these?
//newPlayer.primary =
//newPlayer.secondary =
}
}
I know I could have UI buttons that each call their own method such as:
public CreateNewBlackMage(CharacterClass class)
{
class = new BlackMage();
}
But this is not how I want to do it (would rather not have to create a method for each individual class for 1 line of code if it can be helped!), but unfortunately I'm struggling to come up with a better way.
Answer by tormentoarmagedoom · Aug 31, 2018 at 11:27 AM
Good day.
You can create a Slider for selecting, and one buton to confirm. and just check the slider value to know the selected class
Thanks for the reply. That's better than having multiple methods. I could just use a switch statement. Again I wonder if there is a "better" way. After they select their primary class, I would need another button to call the same method. Although this doesn'the exactly go against the DRY rule, im just wondering if there is a cleaner solution, as I have ended up with spaghetti code when relying upon switch statements. If there are no more answers given, I'll accept this answer. Thanks again
Your answer
![](https://koobas.hobune.stream/wayback/20220612173822im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scroll View Children not Behaving (UI Instantiated Prefabs not conforming to guide) 0 Answers
Weapon arsenal Inventory UI 0 Answers
UI element bug? 1 Answer
RectTransform Left Right Bottom Top 0 Answers
VS Code missing UnityEngine.UI 1 Answer