Unity protected varuable code example
Example: protected variable unity
public class ClassA
{
private string text1;
protected string text2;
public ClassA()
{
text1 = "aaa"; // ok
text2 = "bbb"; // ok
}
}
public class ClassB : ClassA
{
public ClassB()
{
text1 = "aaa"; // compile error - you can't access text1, because it is visible only in scope of ClassA
text2 = "bbb"; // ok - text2 is declared as protected in ClassA, so it is accessible in ClassA and all the classes derived from ClassA
}
}