I am trying to brush up on my C# / XNA and I cannot figure out how to assign a data type at runtime.
I want to refer to all characters by creating a new Character.cs
Then inside of the Character.cs I instantiate a character type and choose a sub-.cs
Here is a representation of what I am used to doing in AS3:
Game1.cs
public Character Char = new Character();
CharType(Char, "Ninja");
public void CharType(Character Char, String chartype)
{
if(chartype == "Ninja")
Char.GameChar = new Ninja();
else if(chartype == "Soldier")
Char.GameChar = new Soldier();
}
Character.cs
var GameChar;
Is this possible in XNA / C#?
To be more clear, I am having trouble have the "var GameChar" in the Character.cs. I cannot find a way to program the variable into the class without first assigning a data type to it. I tried using an 'Object' and 'dynamic' but they wouldn't allow me to access variables within the GameChar variable.
If not, can anyone give me some pointers?