我对 C# 编码相当陌生,正在尝试自学更多。我一直在尝试制作一个简单的角色扮演游戏,其中包含角色扮演游戏中关卡的统计数据,并且一直试图根据我的角色统计数据对敌人施加伤害。
当我认为我已经通过将玩家的统计脚本拆分为敌方单位的第二个统计脚本来解决问题时,不幸的是,我遇到了这样的问题:分配的左侧需要是变量属性或索引器,并且无论我如何寻找解决方案,我都被难住了。有人可以看一下我的脚本并指出我犯的任何明显错误吗?
谢谢,麻烦您了!
public void TakePhysicalDamage()
{
defaultStats.GetPhysicalDamage()-= armor; //This is the offending line
physicalDamage = Mathf.Clamp(physicalDamage, 0, int.MaxValue);
health -= (int)Math.Round(physicalDamage);
if(health <= 0)
{
health = 0;
Die();
}
}
void Die()
{
{
playerLevel.AddExperience(experience_reward);
}
Destroy(gameObject);
}
}
Run Code Online (Sandbox Code Playgroud)
这是playerstats(defaultstats)脚本仅供参考,我试图从中获取物理伤害
[SerializeField] 浮动强度 = 5f; [SerializeField] 浮动物理伤害 = 5f;
public float GetPhysicalDamage()
{
return physicalDamage += strength;
}
Run Code Online (Sandbox Code Playgroud)
抱歉,如果这看起来非常基础,但如果您感到无聊,请看一下!