简体   繁体   English

C#Unity 3D每旋转一整点添加一次

[英]C# Unity 3D add point every full rotation

So i have been looking for about an hour for a solution to my problem and i haven't yet found on so i am on here. 因此,我一直在寻找解决我问题的方法,大约一个小时,但我还没有找到答案,所以我来了。 My problem is that i want to count how many full rotations i do, i have a spinning object, and every full rotation i want to keep a score, i cant calculate the time it takes and then add points on like that, because the speed of the spinning object will be constantly changing, so that wont work. 我的问题是我想计算我做多少个完整的旋转,我有一个旋转的对象,而每个完整的旋转我都想要保持一个分数,我无法计算所需的时间,然后像这样加点,因为速度旋转物体的位置会不断变化,因此无法正常工作。 I would ideally also be able change the angle at which you gain a point. 理想情况下,我也可以更改获得积分的角度。 Or if say every 1 degrees i rotate, it would add a point on like that, anything i would just like to calculate how many times i have rotated. 或者,如果说我每旋转1度,它就会在该点上增加一个点,我想计算出我旋转了多少次。 Any help will be greatly appreciated. 任何帮助将不胜感激。

You can get the current xy or z rotation from your gameobject and then in update you can look if it rotated. 您可以从游戏对象获取当前的xy或z旋转,然后在更新中可以查看其是否旋转。 Example for 10 unit for one point: 1点10个单位的示例:

  1. Your gameobject has rotation equals 20 - save that value in a variable called rot outside the update method. 您的游戏对象的旋转等于20-将值保存在update方法之外的名为rot的变量中。

  2. Update is called. 调用更新。 Your game objects rotation is now 25 - in update you look if the 10 is fitting in 25 - rot. 现在,您的游戏对象旋转角度为25-更新后,您会看到10是否适合25-旋转。 25 - rot is 5 - so doesn t fit. 25-烂是5-不适合。

  3. Update is called. 调用更新。 Your gameobject rotation is now 42 - calculate: 42 - rot is equals 22. You see it fits. 您的游戏对象旋转现在为42-计算:42-腐烂等于22。您会看到它合适。 Now calculate how many times 10 fits into 22. It fits 2 times. 现在计算10适合22的次数。适合2倍。 So add 2 points to the score. 因此,将分数加2分。 Now set rot equals old rot value plus 2 times 10. 现在设置腐烂等于旧腐烂值加2乘以10。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM