so, i guess theres a gap in my understanding. When creating an interface, i have a few properties adn soem methods. The properties are set up like so
string myName { get; set; } // Property interface
then in a class that implements the interface, i define it like so:
public string myName
{
get { return this.myName; }
set { this.myName = value; }
}
however, when accessing the class member, (in some other file) unity crashes
currentScript.init(numPlayers); //this works as intended
currentScript.myName = "someName"; //this crashes unity, i have to restart it
currentScript.changeMyName("someOtherName");//this also crashes unity!
myName.Get calls myName.Get, and so it’ll stack overflow. You need to name your underlying field and your property differently (or use autoimplemented properties). A common practice is lower case first letter for underlying field, capital first letter for property.
Just keep in mind that a Property is a distinct thing, and cannot be named the same as something else (function, variable, etc…). Also that properties don’t actually store anything, and are merely the accessors for somebody else.
If you just want a generically named backing field (because it’s only accessed via the property and the Get/Set doesn’t contain any logic to it) you can use autoimplemented properties:
public string MyName
{get; set;}
Will automatically fill in Get and Set with an auto named variable.