How to make classes?

Hi i was wondering how you could make classes for your character or just have it so that at the char creation screen you can choose a preset thing of stats thank you!!!

If you want to start using classes, the best approach would be C# coding. In that case this is how you write a class:

public class Character
{
   //some example variables
   private float strength;
   private int charID;
   private float health

   //example constructor which sets the default health
   public Character(float hp)
   {
       health = hp;
   }

   //some example functions
   public void someFunction()
   {
       //do stuff
   }

   public int getCharID()
   {
       return charID;
   }
}

since you talked about a character and stats I wrote this example with related variables you might be able to use. If you want to make a character you just use Character char = new Character(100); This makes a new character with 100 health for example

Note: if you want to add the script to an object in the scene, the class should derive from MonoBehaviour like so:

public class Character:MonoBehaviour
{
   ...
}

in this case you shouldn’t use “Character char = new character(100)” (for example) but just drag the script onto the object.

if you want to make an interface to set the stats of the character you should use the OnGUI function (preferably in another class since this is a seperate functionality, for example a class Interface):

public class Interface
{
    void OnGUI()
    {
         // some GUI elements
    }
}

for GUI scripting I refer to this link: http://unity3d.com/support/documentation/Components/gui-Basics.html

Hope this helps :wink:

There is no global definition of a “Class” that all RPGs use to store their presets. It could be anything you define yourself. What is an RPG “Class” in your game? And by asking, I don’t want you to answer me, I want you to ask yourself. Is it the traditional set of Wizard, Fighter, Archer, Thief, Healer, etc? Then, what defines a class? The numbers in Intelligence, Strength, Dexterity and Wisdom? If that is the case, then your preset for a Wizard could be as simple as a textfile called “Wizard” that contains the lines,

Strength: 8 (or something low, for a wizard)

Dexterity: 9 (or something low, for a wizard)

Intelligence: 18 (or something else high, for a wizard)

… You get the point.

Then you can load that into Unity using TextAsset (see http://unity3d.com/support/documentation/ScriptReference/TextAsset.html) and then parse the numbers out of the file. That would be one way to save a preset. On the technical side, there are multiple ways of doing so. You don’t have to save it in a textfile, it could also be hardcoded values in your source code, or it could be rows in an SQL table, to think broadly.

On an unrelated note, I get the impression this is a classic case of “I just started Unity, now let’s make a game that beats World of Warcraft in a week”. :wink: Don’t take this the wrong way, I’m not trying to shoot you or your idea down. But you might benefit a lot from following some of the many tutorials out there, and then maybe coding a smaller project first. Having done so, you’ll realize completely on your own that storing and loading character presets is pretty simple.