简体   繁体   English

当它说分配给它的值从未在 C# 中读取时,我该如何解决?

[英]How do I fix when it says value assigned to it is never read in C#?

Hi I'm new in programming in c#, I just want to know how to fix this issue because I can't increment the value of the points in the game that I am making...嗨,我是 C# 编程新手,我只想知道如何解决这个问题,因为我无法增加我正在制作的游戏中的点值......

using UnityEngine;
public class GameManager: MonoBehaviour
{
   private int point;
   public void IncreaseScore()
   {
       point++;
   }
}

view image看图

It's just a hint, so it doesn't stop you from run this code.这只是一个提示,因此它不会阻止您运行此代码。 However to fix, as information suggests you should read point property by for example assigning it to some value:但是要修复,因为信息表明您应该通过例如将其分配给某个值来读取point属性:

int someValue = point;

If you want this field to be obtainable by other classes in code, you can add public method for it and adding it will resolve your issue too:如果您希望此字段可由代码中的其他类获取,您可以为其添加public方法,添加它也将解决您的问题:

using UnityEngine;
public class GameManager: MonoBehaviour
{
   private int point;

   public int GetScore() => point;
   public void IncreaseScore()
   {
       point++;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM