你好,任何人都可以告诉我......
if (distance < 0.50f) {
theHM.PlayerCurrentHealth --;
currentaDamage = damageToGive - (thePS.currentDefence);
if (currentaDamage < 0) {
currentaDamage = 0;
}
}
这可以正常工作,但它只会导致-1 CurrentHealth。我想 - 目前的伤害,
如果我这样做的话:
if (distance < 0.50f) {
theHM.PlayerCurrentHealth - currentaDamage;
currentaDamage = damageToGive - (thePS.currentDefence);
if (currentaDamage < 0) {
currentaDamage = 0;
}
}
我遇到错误CS0201:只能将赋值,调用,递增,递减和新对象表达式用作语句
答案 0 :(得分:2)
问题出在以下几行:
theHM.PlayerCurrentHealth - currentaDamage;
应该改写为:
theHM.PlayerCurrentHealth = theHM.PlayerCurrentHealth - currentaDamage;
为什么这样?因为您想要PlayerCurrentHealth
递减currentaDamage
,PlayerCurrentHealth
应该具有vew值。
以下内容:
theHM.PlayerCurrentHealth--;
相当于
theHM.PlayerCurrentHealth = theHM.PlayerCurrentHealth - 1;