我有以下(相关)代码:
public class GameController : MonoBehaviour {
public class Timer
{
int elapsedTime;
int pausedTime;
bool isCounting;
public void Start()
{
int startTime = DateTime.Now.Millisecond;
while(isCounting)
{
elapsedTime = DateTime.Now.Millisecond - startTime;
}
}
}
private void Update()
{
//Debug logging of the timer functions
if(startButton.CompareTag("Clicked"))
{
Timer.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
}
此代码生成以下错误:非静态字段,方法或属性'GameController.Timer.Start()`需要对象引用.我怎样才能解决这个问题?
(注意:对于几乎每种情况,此错误的原因都不同,因此很难将其称为重复.)