我有一個基本的類設置的項目,收到一些損害,並有一個健康狀況。但由於某些原因,我無法訪問基本變量,因爲我無法訪問錯誤。訪問基類變量無法訪問的錯誤
這是我的代碼設置:
public abstract class Items
{
public float health { get; private set; }
public Items()
{
health = 100f;
}
}
public class Sword : Items
{
public string name { get; private set; }
public float maxPower { get; private set; }
public Sword(string n float mPower) : base()
{
name = n;
maxPower = mPower;
}
public void UpdateDamage(float damageAmount)
{
health = Mathf.Clamp(health - damageAmount,0,100);
}
}
的錯誤是:
'Items.health' 不可訪問由於其保護級別
我推測,因爲我設置它公開我可以在我的損害方法訪問它,但我猜不是。我在哪裏錯了?
@Dabe - 我還建議您在這裏閱讀[c#命名轉換](https://msdn.microsoft.com/en-us/library/ms229002(v = vs.110).aspx) –