【发布时间】:2014-10-28 23:41:20
【问题描述】:
我正在编写带有一些动画的游戏,并在用户单击按钮时使用这些动画。我想向用户展示动画,而不是“只是”用 Application.loadLevel 调用一个新级别。我想我可以在 onMouseUp 方法中使用 Time.DeltaTime 并将其添加到预定义的 0f 值,然后检查它是否大于(例如)1f,但它只是不起作用,因为 onMouseUp 方法只添加了“它是自己的时间”作为增量时间。
我的脚本现在看起来像这样:
public class ClickScriptAnim : MonoBehaviour {
public Sprite pressedBtn;
public Sprite btn;
public GameObject target;
public string message;
public Transform mesh;
private bool inAnim = true;
private Animator animator;
private float inGameTime = 0f;
// Use this for initialization
void Start () {
animator = mesh.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
}
void OnMouseDown() {
animator.SetBool("callAnim", true);
}
void OnMouseUp() {
animator.SetBool("callAnim", false);
animator.SetBool("callGoAway", true);
float animTime = Time.deltaTime;
Debug.Log(inGameTime.ToString());
// I would like to put here something to wait some seconds
target.SendMessage(message, SendMessageOptions.RequireReceiver);
}
}
}
【问题讨论】:
-
Thread.Sleep(1000) 将等待一秒钟,您是否正在寻找类似的东西?
-
您尝试等待一段时间的代码在哪里?
-
正如我所写的,我尝试将 inGameTime += Time.deltaTime 放入 onMouseUp() 方法,但它没有按预期工作,因为 OnMouseUp 方法只返回一个最小的 deltaTime跨度>
-
您不想在处理用户输入时等待。如果您希望动画延迟,那么为什么不使用启动时什么都不做(对于某些帧数)的动画?