操作符“* & # 39;不能应用于' method group'和“浮动# 39;
本文关键字:浮动 group method 不能 操作符 应用于 | 更新日期: 2023-09-27 17:50:11
我正在跟随BurgZergArcade教程学习如何创建一个Hack'N'Slash游戏。在此期间,我遇到了一个错误,如果有人能帮助我,我将非常感激。语言是c#。
错误:Assets/Scripts/Character Classes/ModifiedStat.cs(21,66):错误CS0019: Operator *' cannot be applied to operands of type
method group' and ' float'
public class BaseStat {
public class BaseStat {
private int _baseValue; //The base value of this stat
private int _buffValue; //The amount of buff to this stat
private int _expToLevel; //Thetotal amount of exp needed to raise this skill
private float _levelModifier; //The modifier applied to the exp needed to raise the skill
public BaseStat() {
_baseValue = 0;
_buffValue = 0;
_levelModifier = 1.1f;
_expToLevel = 100;
}
public int BaseValue{
get{ return _baseValue; }
set{ _baseValue = value; }
}
public int BuffValue{
get{ return _buffValue; }
set{ _buffValue = value; }
}
public int ExpToLevel{
get{ return _expToLevel; }
set{ _expToLevel = value; }
}
public float LevelModifier{
get{ return _levelModifier; }
set{ _levelModifier = value; }
}
private int CalculateExpToLevel() {
return (int)(_expToLevel * _levelModifier);
}
public void LevelUp() {
_expToLevel = CalculateExpToLevel();
_baseValue++;
}
public int AdjustedValue() {
return _baseValue + _buffValue;
}
}
public class Atrribute : BaseStat {
public Atrribute() {
ExpToLevel = 50;
LevelModifier = 1.05f;
}
}
public enum AttributeName{
Might,
Constitution,
Nimbleness,
Speed,
Concentration,
Willpower,
Charisma
}
public class ModifiedStat : BaseStat {
private List<ModifyingAttribute> _mods; //A list of Attributes that modify this stat
private int _modValue; //
public ModifiedStat(){
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier( ModifyingAttribute mod ) {
_mods.Add(mod);
}
private void CalculateModValue() {
_modValue = 0;
if(_mods.Count > 0)
foreach( ModifyingAttribute att in _mods )
_modValue += (int)(att.attribute.AdjustedValue * att.ratio);
}
}
public struct ModifyingAttribute {
public Atrribute attribute;
public float ratio;
}
由于BaseState.AdjustedValue
是一个方法,我将ModifiedStat.CalculateModValue()
中的行更改为:
_modValue += (int)(att.attribute.AdjustedValue() * att.ratio);
请注意AdjustedValue
后面的()