【发布时间】:2023-03-28 18:58:01
【问题描述】:
我让我的对象向一个方向移动,并在它到达位置 10 时将 z 位置重置为 0。但是当它到达 10 时位置 z 并没有返回到 0。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class NewBehaviourScript : MonoBehaviour
{
float z = 1.0F;
void Update()
{
if (z < 10.0f)
{
//move object forward
transform.Translate(0,0,z * Time.deltaTime * 0.5F);
}
else
{
z = 0;
}
}
}
【问题讨论】:
-
z == 0是返回true或false的比较。单独,它是无效的代码。也许你想要一个任务(即z = 0)?