【发布时间】:2016-03-24 03:39:13
【问题描述】:
我最初发生了一个转换(施加的力移动对象),然后用户使用DownArrow 对其进行响应。我希望最初的transform.up 在设定的时间间隔内随机发生,并不断循环,以便用户可以继续响应它。
using UnityEngine;
using System.Collections;
public class thingBumps : MonoBehaviour {
public float thrust;
public Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.AddForce (transform.up * thrust, ForceMode.Impulse);
if (Input.GetKey(KeyCode.DownArrow))
rb.AddForce(-transform.up * thrust,ForceMode.Impulse);
}
}
我已经尝试过 Coroutines 和 InvokeRepeating,但我很难过,我已经阅读了有关该主题的每个线程。我只希望第一个transform.up 以随机时间间隔重复,以便用户可以继续响应它(使用他们自己的transform.up 转换)。有谁知道如何做到这一点?
感谢任何建议。
【问题讨论】:
-
你所说的“在设定的时间间隔内的随机时间,然后循环”是什么意思?