运营商`*'不能应用于`method group'类型的操作数并且`浮动'

时间:2014-03-14 09:50:53

标签: c# unity3d

我正在关注如何创建Hack'N'Slash游戏的BurgZergArcade教程。在此期间,我遇到了一个错误,如果有人能帮助我,我将非常感激。语言是c#。

错误:Assets / Scripts / Character Classes / ModifiedStat.cs(21,66):错误CS0019:运算符*' cannot be applied to operands of type方法组'和'浮动'

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;
}

1 个答案:

答案 0 :(得分:3)

由于BaseState.AdjustedValue是一种方法,我会将ModifiedStat.CalculateModValue()中的行更改为:

_modValue += (int)(att.attribute.AdjustedValue() * att.ratio);

请注意()后的AdjustedValue