【发布时间】:2021-10-16 05:24:49
【问题描述】:
在过去的几天里,我一直在尝试制作一个简单的飞鸟游戏。目前,我正在尝试编写一些代码,让玩家每次通过两个管道时得分都会上升。不过我遇到了一个错误,我不太确定如何解决它。这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Score : MonoBehaviour {
public static int score = 0;
private void Start() {
score = 0;
}
private void Update() {
GetComponent<UnityEngine.UI.Text>().text = score.ToString();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddScore : MonoBehaviour {
private void OnTriggerEnter2D (Collider2D collision) {
Score.score++; // This is the line that's giving me errors
}
}
我得到的确切错误是 - 错误 CS0117:“分数”不包含“分数”的定义。我有点困惑的原因是因为在 Vistual Studio Code 上它实际上并没有显示任何错误。该错误仅在我尝试运行游戏时出现。
任何帮助将不胜感激。
【问题讨论】:
-
CS0117是 编译时间 错误 =>The error only appears when I try to run the game.我怀疑...
标签: unity3d