- Home /
Switching between multiple classes
Hello,
I'm currently working on a game where I want the player to be able to choose (before the start of the game) a character. It's a fantasy game so it's basically a mage and a warrior so far. Note that it's in another scene that the choice is made and not in the level.
It works kinda like Skyrim with a First Person View so I have no models.
I have a character selection screen that brings me to the level 1 but my biggest problem is te object switching between the two characters since they have a whole bunch of scripts attached to them and I don't really know how to disable everything from 1 to use everything from the other. My characters move at different speeds, don't have the same life or mana or anything really.
I figured I probably don't have to switch camera since I want to spawn exactly at the same place for both but except this part I don't really know what I should do. I really want to remove everything linked to the mage from the world if the warrior is called for example and a simple Destroy object doesn't work.
Can you help me with this one?
Just a note: Your two characters (in fact, all of them) should have the same script/class, or at least inherit from the same class. That means you can generalize world interactions and don't have to switch scripts depending on which character the player has chosen.
Well, they do have the same basics yeah like some part of their mouvements or some part of the GUI but my mage as a few spells that I have to disable for my warrior for example. Anyways I think I found the solution I destroy the object I don't need and I put "if($$anonymous$$age)" with a public static bool variable everywhere in the scripts for the part I don't need to have for the warrior. But not being a programmer, I have a feeling that it is an ugly way to do it.
Yes, that is a very ugly way of doing it. I already mentioned inheritance as a good way of doing it. I don't know anything about how it's supposed to be set up, but maybe you should try inheritance.
I'll try to look into it, I'm not too familiar with inheritance I just know the basic concept.
Thank you.
Answer by blank_reg · Jan 24, 2014 at 12:05 AM
You could use SetActive on your characters. Read about it in the Scripting Reference
I tried before posting here but it didn't work like I wanted too.
maybe you can post your code, or link to original posting if there is code there. It should be pretty straightforward.
Answer by Valon · Jan 24, 2014 at 02:40 AM
Ok so this is the character spawner :
int savedPlayer = 0;
GameObject Character1;
GameObject Character2;
public static bool isMage = true;
bool isPrincipal = false;
void Awake()
{
Character1 = GameObject.Find ("Mage");
Character2 = GameObject.Find ("Guerrier");
savedPlayer = PlayerPrefs.GetInt ("selected Character");
if (savedPlayer == 1) {
Character1.SetActive(true);
GameObject.Destroy(Character2);
isMage = true;
}
if (savedPlayer == 2) {
Character2.SetActive(true);
GameObject.Destroy(Character1);
isMage = false;
}
if (savedPlayer == 0) {
Character1.SetActive(true);
GameObject.Destroy(Character2);
isMage = true;
}
}
}
And this is the character selector, I actually used SetActive but I think it's the part where it has to put is to false that doesn't work :
public bool isCharacter1 = false;
public bool isCharacter2 = false;
public bool isCharacter3 = false;
public bool isCharacter4 = false;
int nbCharacter = 4;
int selectedCharacter = 0;
void OnMouseUp()
{
if (isCharacter1) {
selectedCharacter = 1;
PlayerPrefs.SetInt("selected Character", selectedCharacter);
Application.LoadLevel("Tomjeu");
}
if (isCharacter2) {
selectedCharacter = 2;
PlayerPrefs.SetInt("selected Character", selectedCharacter);
Application.LoadLevel("Tomjeu");
}
if (isCharacter3) {
selectedCharacter = 3;
PlayerPrefs.SetInt("selected Character", selectedCharacter);
}
if (isCharacter4) {
selectedCharacter = 4;
PlayerPrefs.SetInt("selected Character", selectedCharacter);
}
}
}
Your answer
Follow this Question
Related Questions
Realtime object loading to scene 1 Answer
switch character 1 Answer
Recommendation for very simple character customization? 0 Answers
Rerolling RPG Character Attributes With Limits 1 Answer
Character Selection 0 Answers