- Home /
Creating an Object of another class inside a class
Hi, all! In my game I have several classes (Gun, player, etc). One such class is SaveSlot.
There are 3 SaveSlots, and so the SaveSlot contains the data relevant to each save slot. It contains the gun and all of their properties (cost, upgrade, etc) and same with the player.
There is of course a save / load function in the game (Ahem, there WILL be ). It is in a script called master. One such object of the SaveSlot class is `ship : Player;`
The Player class has a constructor, but I do not know how to call it upon instantiation of the SaveSlot without having things get really sloppy.
As I see it I have two routes:
Create temporary variables that are objects for every Gun, and another one for the player, and pass them into the SaveSlot's constructor.
Have a ridiculously long constructor for the save slot
Which way is the better way to go? Thanks! - YA
Answer by nventimiglia · Dec 02, 2012 at 06:37 PM
<!?!??!?!!wtf?!?!?!?!?>
public class Zoo{
protected class Animal{
public string Name {get;set;}
}
public void Zoo(){
var cat = new Animal{Name = "Cat"};
var dog = new Animal{Name = "Dog"};
}
}
</!?!??!?!!wtf?!?!?!?!?>
What is a protected class? And thank you for the reply!
Your answer
Follow this Question
Related Questions
Distance between 2 objects 1 axis 2 Answers
Component or Independent class 1 Answer
Monobehavior vs other classes? 1 Answer
what is the problem of this code ? 2 Answers
Make Deaths end game 1 Answer