C#增加一个计数器 [英] C# To incremente a counter

查看:559
本文介绍了C#增加一个计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计数器不会增加。

我尝试在不同的地方移动或移出花括号的增量,并且它不会运行:



The counter frame doesn't incremente.
I try to move the increment in or out curly braces, at different places, and it doesn't run:

void FixedUpdate() {

    delta_time += Time.deltaTime;

    if (frame < nv_data [0].positions.Length) {

        for (int k = 0; k < Ensemble.Length; ++k) {

            if (Ensemble [k] != null) { 

                Ensemble[k].transform.localPosition = nv_data[k].positions[frame];

            } else

                continue;

        }

        Debug.Log (frame); // I have always 0

        if (frame < forces_dup.Length) {

            if (frame >= 1) {

                double delta_x = ((nv_data [12].positions [frame] - nv_data [12].positions [frame - 1]).x);
                vitesse = delta_x / Time.deltaTime;
                acceleration = (vitesse-ancienne_vitesse)/Time.deltaTime;
                ancienne_vitesse = vitesse;

                StreamWriter writer = new StreamWriter ("Accelerations_5Hz.txt", true);

                using (writer) {

                    writer.WriteLine(Time.time + "\t" + (86*acceleration) + "\t" + forces_dup[frame].z);
                }

            }

        }

        frame++;

    }

}

推荐答案

代码中有太多未知数让我们可能知道发生了什么。 框架的定义在哪里,它的初始值是多少?什么是nv_data?它里面有多少件物品?什么是posisionts以及nv_data [0]中有多少位置?什么是合奏,它的长度是多少?什么是转换等等。我们无法远程调试您的代码,熟悉使用调试器逐步执行代码,检查变量等,您应该能够解决正在发生的事情。



掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]
There are too many unknowns in your code for us to possibly know what is going on. Where is "frame" defined and what is its initial value? What is nv_data? How many items are in it? What is "posisionts" and how many "positions" are in nv_data[0]? What is Ensemble and what is its length? What is transform etc etc etc. We can't debug your code remotely, get familiar with stepping through your code using the debugger, inspecting variables etc and you should be able to work out what is happening.

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]


根据我的评论,这是我的想法:



(我们需要看到全班确认这个btw)



frame 一个类int?像这样:



As per my comment, this was my idea:

(We need to see the whole class to confirm this btw)

is frame a class int? like this:

class myclass{
 int frame;
...
}





并且是每次实例化为新的类,如:



and is the class instantiated as new each time like:

var myvar = new myclass();





如果是这种情况,那么每次实例化类时帧都将为零。如果你希望值保持不变并且仍然使用 myclass ,那么你需要 static int frame



我错过了那个标记了吗?这主要是在没有看到你写的全班的猜测工作。



if that is the case then frame will be zero every time you instantiate the class. If you want the value to persist and still use myclass this way then you need static int frame.

Did I miss the mark on that one? This is mostly guess work without seeing the whole class you have written.


这篇关于C#增加一个计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆