C#增加一个计数器

编程入门 行业动态 更新时间:2024-10-09 15:17:20
本文介绍了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#增加一个计数器

本文发布于:2023-10-18 15:31:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计数器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!