gpt4 book ai didi

c# - 为什么我不能使用 stopwatch.Restart()?

转载 作者:太空狗 更新时间:2023-10-29 22:12:00 26 4
gpt4 key购买 nike

我正在尝试在秒表实例上调用 Restart(),但在尝试调用它时出现以下错误:

Assets/Scripts/Controls/SuperTouch.cs(22,59): error CS1061: Type System.Diagnostics.Stopwatch' does not contain a definition for
Restart' and no extension method Restart' of type
System.Diagnostics.Stopwatch' could be found (are you missing a using directive or an assembly reference?)

这是我的代码:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Controls
{

public class SuperTouch
{
public Vector2 position { get { return points [points.Count - 1]; } }
public float duration { get { return (float)stopwatch.ElapsedMilliseconds; } }
public float distance;
public List<Vector2> points = new List<Vector2> ();

public Stopwatch stopwatch = new Stopwatch ();

public void Reset ()
{
points.Clear ();
distance = 0;
stopwatch.Restart ();
}
}
}

最佳答案

我猜您使用的是 4.0 之前的框架,这意味着您必须使用 ResetStart 而不是 Restart

关于c# - 为什么我不能使用 stopwatch.Restart()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27913664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com