C# 数学函数c的统一性

C# 数学函数c的统一性,c#,function,unity3d,C#,Function,Unity3d,我试图让ShareScreenshotWithText在每次调用来自不同脚本settings.ScreenShotInterval的浮点时调用。现在我的代码是 (scoreTeam1 + scoreTeam2 == settings.screenshotintervals * (1) | scoreTeam1 + scoreTeam2 == settings.screenshotintervals * 2 | scoreTeam1 + scoreTeam2 == settings.screens

我试图让ShareScreenshotWithText在每次调用来自不同脚本settings.ScreenShotInterval的浮点时调用。现在我的代码是

(scoreTeam1 + scoreTeam2 == settings.screenshotintervals * (1) | scoreTeam1 + scoreTeam2 == settings.screenshotintervals * 2 | scoreTeam1 + scoreTeam2 == settings.screenshotintervals * 3 | scoreTeam1 + scoreTeam2 == settings.screenshotintervals * 4 

他们有没有其他更简单的方法来做这件事,然后把它打出来,但每次都改变数字?另一个脚本有一个滑块,用户可以更改该滑块的值。

您可以生成数字范围,并检查这些数字中的任何一个乘以间隔是否会得到分数总和:

Enumerable.Range(1,4).Any(i => settings.screenshotintervals * i == scoreTeam1 + scoreTeam2)
抱歉,我没有注意到值是浮动的。正如@Everts所述,这里最好的解决方案是使用值比较:

var totalScore = scoreTeam1 + scoreTeam2;
var result = Enumerable.Range(1,4)
       .Any(i =>  Mathf.Approximately(settings.screenshotintervals * i, totalScore));

“按位”或“有”看起来很可疑。如果这些是浮点数,则不太可能出现浮点数不准确的情况。使用Mathf.approxist会有所帮助。