C# 激光测距仪不能统一工作。为什么?
我的代码因为某种奇怪的原因不起作用。它没有犯任何错误,但没有拍摄任何东西,调试日志也不工作C# 激光测距仪不能统一工作。为什么?,c#,unity3d,C#,Unity3d,我的代码因为某种奇怪的原因不起作用。它没有犯任何错误,但没有拍摄任何东西,调试日志也不工作 void Start() { LaserRoutine(); } // Update is called once per frame void Update() { } IEnumerator LaserRoutine() { while (true) { for (var i = 0; i < 3; i++) {
void Start()
{
LaserRoutine();
}
// Update is called once per frame
void Update()
{
}
IEnumerator LaserRoutine()
{
while (true)
{
for (var i = 0; i < 3; i++)
{
for (var j = 0; j < 5; j++)
{
SpawnLaser();
}
Debug.Log("Spawned");
yield return new WaitForSeconds(0.5f);
}
yield return new WaitForSeconds(3);
}
}
void SpawnLaser()
{
Vector3 pos = transform.position;
Instantiate(projectile,pos,transform.rotation);
}
void Start()
{
LaserRoutine();
}
//每帧调用一次更新
无效更新()
{
}
IEnumerator LaserRoutine()
{
while(true)
{
对于(变量i=0;i<3;i++)
{
对于(var j=0;j<5;j++)
{
激光();
}
Log(“派生”);
收益率返回新的WaitForSeconds(0.5f);
}
产生返回新WaitForSeconds(3);
}
}
真空激光器()
{
向量3位置=变换位置;
实例化(投射、位置、变换、旋转);
}
要让枚举数执行某项操作,必须对其进行迭代。在Unity中,这可以通过startcroutine
void Start()
{
StartCoroutine(LaserRoutine());
}
看
原因是(一个具有
收益率返回的方法
)只是一个等待迭代的设置。它本身不做任何事情。您需要使用start例程(LaserRoutine())代码>