unity3d - 即使游戏暂停且时间刻度设置为 0,协程仍会运行
问题描述
正如标题所指出的,由于某种原因,当我的游戏暂停时,我的协程仍然运行。我什至将时间尺度条件置于一段时间条件下,以便在暂停时不会运行,但无济于事。我已经完整地添加了我的代码,希望有人能够提供帮助。
using UnityEngine;
using System.Collections;
using Chronos;
public class ObjectSpawn : BaseBehaviour //MonoBehaviour
{
public float minTime = 3f;
public float maxTime = 9f;
public float minX = -65.5f;
public float maxX = -5.5f;
public float topY = -5.5f;
public float z = 0.0f;
public int count = 50;
public GameObject prefab;
public bool doSpawn = true;
public float fallGrav =1.0f;
int first = 1;
void Start()
{
Clock clock = Timekeeper.instance.Clock("MovingOneWayPlatforms");
StartCoroutine(Spawner());
}
IEnumerator Spawner()
{
while (first == 1) {
yield return time.WaitForSeconds(8.0f);
first = 0;
}
while (doSpawn && count > 0 /*&& time.timeScale != 0 */)
{
Renderer renderer = GetComponent<Renderer>();
float min = renderer.bounds.min.x;
float max = renderer.bounds.max.x;
Vector3 v12 = new Vector3(Random.Range(minX, maxX), this.gameObject.transform.position.y, 0f);
prefab.GetComponent<Rigidbody2D>().gravityScale = fallGrav;
prefab = Instantiate(prefab, v12, Random.rotation);
count--;
// yield return new WaitForSeconds(Random.Range(minTime, maxTime));
yield return time.WaitForSeconds(Random.Range(minTime, maxTime));
Destroy(prefab, 6);
}
}
}
解决方案
尝试取消注释您的第二个 while 语句,我认为这是您的问题。
推荐阅读
- c++ - 有没有更好的方法可以接收这个输入?C++
- sql - 没有附加查询的答案?
- pytorch - 为什么我在测试集上收到 Pytorch 运行时错误
- android - Android 使用 mime 类型 GIF 保存 MediaStore 图像
- c++ - PN532 试图从 Felica 标签获取设备型号
- powershell - 如何使用 powershell 脚本从保存的文件中恢复 Windows 中的语言设置?
- c# - 如何通过 Autofac 模块配置 Masstransit 消费者
- html - 使不同 Flexbox 列中的行具有相同的高度
- vba - 如何使宏忽略表?
- javascript - Uncaught (in promise) SyntaxError: Unexpected token ] in JSON at position 3569