我有以下代码
public class Score : MonoBehaviour {
private static int score;
public int sc;
void OnTriggerEnter2D(Collider2D col) {
if (col.tag == "Ball") {
score++;
sc = score;
}
}
这是我用来从上面的课程中得分的课程
public class ScoreText : MonoBehaviour {
Score s = new Score();
int sc;
void Update () {
sc = s.sc;
}
}
但由于某些原因,我在ScoreText类中的sc变量始终为0.我该如何解决?
答案 0 :(得分:0)
您可以使用class.property
获取静态变量的值SELECT {fn HOUR(GETDATE())} AS hour
更改私有静态int分数; for public static int score;
答案 1 :(得分:0)
将private static int score;
更改为public static int score;
并将其称为:Score.score = 5;
如果要将其用作属性,可以执行以下操作:
private static int _score;
public int score {
get{return _score;}
set{_score = value;}
}