C# 错误CS0201:仅分配,呼叫

C# 错误CS0201:仅分配,呼叫,c#,C#,您好,有人能告诉我这个吗 if (distance < 0.50f) { theHM.PlayerCurrentHealth --; currentaDamage = damageToGive - (thePS.currentDefence); if (currentaDamage < 0) { currentaDamage = 0; } } if(距离

您好,有人能告诉我这个吗

 if (distance < 0.50f) {
     theHM.PlayerCurrentHealth --;
     currentaDamage = damageToGive - (thePS.currentDefence);
     if (currentaDamage < 0) {
         currentaDamage = 0;
     }
 }
if(距离<0.50f){
他们是玩家的本钱健康--;
currentaDamage=damageToGive-(PS.CurrentDefense);
如果(当前图像<0){
currentaDamage=0;
}
}
这工作正常,但只会导致-1 CurrentHealth。我想知道当前的损失

如果我愿意这样做:

 if (distance < 0.50f) {
     theHM.PlayerCurrentHealth - currentaDamage;
     currentaDamage = damageToGive - (thePS.currentDefence);
     if (currentaDamage < 0) {
         currentaDamage = 0;
     }
 }
if(距离<0.50f){
玩家当前健康-当前图像;
currentaDamage=damageToGive-(PS.CurrentDefense);
如果(当前图像<0){
currentaDamage=0;
}
}

我有一个错误CS0201:只有赋值、调用、增量、减量和新对象表达式可以用作语句

theHM.PlayerCurrentHealth - currentaDamage;
应将其改写为:

theHM.PlayerCurrentHealth = theHM.PlayerCurrentHealth - currentaDamage;
为什么会这样?因为您想将
PlayerCurrentHealth
的值减少
currentaDamage
,而
PlayerCurrentHealth
应该具有vew值

以下是:

theHM.PlayerCurrentHealth--;
相当于

theHM.PlayerCurrentHealth = theHM.PlayerCurrentHealth - 1;

但是这是什么-
theHM.PlayerCurrentHealth-currentamage应该怎么做?你只是从一个值中减去另一个值,你没有把它存储在任何地方,这是编译器试图告诉你的。你的意思是在计算之前减去当前的损害吗?是的,我在c#方面不强。是的无效更新(){currentaDamage=damageToGive-(thePS.currentDefense);if(currentaDamage<0){currentaDamage=0;}如果(attackTimer>0)attackTimer-=Time.deltaTime;如果(attackTimer-Since
-=
不是您需要的,那么您需要解释您想要什么,而不仅仅是“此代码不工作”.奇怪的否决。这正是问题所在。有时需要解释。enymore没有错误,但不是PlayerHPI的get-currDmg。希望你没有因为一个简单的打字错误就否决。一条评论或一次编辑就足够了(在我看来)如果我喜欢:theHM.PlayerCurrentHealth=theHM.PlayerCurrentHealth-1;那么它是有效的。但是:theHM.PlayerCurrentHealth=theHM.PlayerCurrentHealth-currentaDamage;不起作用