本文介绍了Mathf.Mathf.大约不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码用于移动通过游戏并更改背景的雾精灵.事实是Mathf.Property不会返回true.关于为什么发生这种情况的任何想法,或者如何在不对位置值进行硬编码的情况下解决该问题.
I have the following code for moving a fog sprite that passes trough the game and changes the background. The thing is that Mathf.Approximately does not return true. Any ideas why this is happening or how can I work around this without hard coding the position values.
fog.transform.position = new Vector3(Mathf.Lerp(fog.transform.position.x,gameObject.transform.position.x,transitionTime * Time.deltaTime),
gameObject.transform.position.y, 0f);
if (Mathf.Approximately(fog.transform.position.x, backGround.transform.position.x))
{
index++;
currentBackround.sprite = enviroments[index];
Debug.Log(index);
}
if (Mathf.Approximately(fog.transform.position.x, gameObject.transform.position.x))
{
fog.transform.position = startPos;
}
推荐答案
我通过编写自己的近似值来解决它,但是我仍然对为什么Mathf.Alternate不起作用感兴趣.这是我编写的代码
I solved it by writing my own approximation, but I'm still interested in why Mathf.Approximately does not work. Here is the code that I wrote
private bool myApproximation(float a, float b, float tolerance)
{
return (Mathf.Abs(a - b) < tolerance);
}
这篇关于Mathf.Mathf.大约不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!