- Home /
Create-a-Class?
I want to be able to have multiple classes (or loadouts) for my game. Is there anyway I can do this? One idea i had would be to store the original prefabs in the deep parts of the game then as you level up and get more things you can bring up that model that has an extension on it. I want this to also affect one person not a whole bunch of people. (im trying to get my hand at multiplayer scritping and i dont get how to make the script affect only one person (but thats another question). So How do i get this create a class function working here?
Answer by fafase · Aug 18, 2012 at 08:16 AM
I don't get quite well everything you say so I will answer with what I understood.
You can create classes, simply create a script with the declaration of a class and the other one will automatically access:
In one script
class Boy{
var age:int;
var toy:String;
function Boy(a:int,s:String){// Constructor
age = a;
toy =s;
}
function Play(){
print(name+" is "+age+ " and plays with his "+toy);
}
}
class Girl{
var age:int;
var toy :String;
function Boy(a:int,s:String){ // Constructor
age = a;
toy=s;
}
function Play(){
print(name+" is "+age+ " and plays with her "+toy);
}
}
Then anywhere else:
var steve = new Boy(10, "GIJoe");
var kelly = new Girl(8, "Barbie");
Now each of them will be a total different object in memory with special addresses for each variable.
Then you can use the variables like:
steve.toy = "Lego";
steve.Play();
kelly.age = 22;
kelly.toy = "well...";
kelly.Play();
Is that what you meant?
I don't mean how do you declare a class in script(Though thanks because I'm sure i'm going to need this knowledge sooner or later) But what I mean is if you play a game like Call of Duty the feature Create-a-Class where you make custom loadouts is what I'm talking about here.
If you dont know this will explain it: http://callofduty.wikia.com/wiki/Create-A-Class
I would think the principle remains the same. You have the class and a particular action, clicking a button in a zone of the menu, will create the object with the information you gave. Those info could be free or a choice within an enumerator. Later you would have to save the info. This is not impossible but that is quite a long process since you need to declare all the possible choices, create the GUI and the saving system.