单击向上箭头后,我如何才能使它保持运动状态?如果再次单击向上箭头,它应该会获得动力。我相信这应该发生在 FixedUpdate 中。当开枪时,“Fire1”的 if 语句会发生这种情况,但我需要对象本身保持运动状态。
float hInputValue;
float vInputValue;
float angle;
float RotationSpeed;
public GameObject target;
public GameObject circlePrefab;
void Start()
{
angle = 0f;
RotationSpeed = -2.5f;
}
void Update()
{
hInputValue = Input.GetAxis("Horizontal");
vInputValue = Input.GetAxis("Vertical");
float zRotValue = hInputValue * RotationSpeed;
angle += zRotValue;
if (Input.GetButtonDown("Fire1"))
{
Vector3 circlePosition = transform.position + new Vector3(0f, 0.75f);
Quaternion circleRotation = new Quaternion();
GameObject CircleObject = Instantiate(CirclePrefab, circlePosition, circleRotation);
circleMover mover = circleObject.GetComponent<circleMover>();
Vector3 circleForce = new Vector3(0f, 0.04f, 0f);
mover.ApplyForce(circleForce);
}
}
private void FixedUpdate()
{
float y = transform.position.y;
y += vInputValue;
Quaternion rotation = Quaternion.Euler(0f, 0f, angle);
transform.rotation = rotation;
transform.position = new Vector3(transform.position.x, y);
Vector3 targetVector = new Vector3(0f, 4f);
targetVector = rotation * targetVector;
target.transform.position = targetVector;
CirclePrefab.transform.position = targetVector;
}
我在 FixedUpdate 中尝试了 applyForce,但没有任何反应。