【发布时间】:2020-04-20 15:22:49
【问题描述】:
我试图让一个角色移动一定距离,然后在他们移动一定距离时改变方向......我的代码中的逻辑可能是错误的我仍然需要处理这不是问题,问题是我的 if 语句没有执行
public class EnemyControl : MonoBehaviour
{
private int xMoveDirection=-1;
private float x;
void Start()
{
x=gameObject.transform.position.x;
}
void Update()
{
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(xMoveDirection,0);
if(x==0.00){
Debug.Log("helloimhere");
xMoveDirection=0;
x=x+1;
}
【问题讨论】:
-
此时
x的值是多少?你能在“if”之前添加Debug.Log($"x = {x}")之类的东西吗? -
@DougDawson Debug 的 if 语句之前的 x 值显示为 4.13
-
但是如果你说
x是4.13那么你为什么期望if语句会执行呢?
标签: c# unity3d game-physics