- Home /
This question was
closed Jul 06, 2014 at 10:32 PM by
QuestionAsker for the following reason:
The question is answered, right answer was accepted
Question by
QuestionAsker · Sep 01, 2013 at 02:07 AM ·
classinheritancepropertiesgetset
C# Parent-SubClass set inherited properties help
So I'm struggling to grasp this whole get; set; properties thing. Specifically,
public class Gun : MonoBehaviour {
public string gunName { get; set; } //"BLANK";
public string UID { get; set; } //"000AAA000AAA";
public string weaponType { get; set; } //"BLANK";
}
Is my parent
public class M9 : Gun
{
public string gunName = "M9";
public string UID = "00AA00AA";
public string weaponType = "HandGun";
}
Is the child. I'm trying to set the properties in my main Gun class and specify those properties' values in any child classes.
I've tried so many things, and I can't get it right. If I wasn't clear on my issue please ask! Thanks!
Comment
Best Answer
Answer by citizen_rafiq · Sep 01, 2013 at 02:37 AM
public class Gun :MonoBehaviour{ public string GunName { get; set; } }
public class M9 : Gun {
public string gunName;
void Awake(){
this.GunName="my_gun";
}
void OnEnable(){
print(this.GunName);
}
}