繁体   English   中英

为什么Debug.Log在此for循环中不起作用?

[英]Why doesn't Debug.Log work in this for loop?

这就是我所拥有的。 此DrawPoints()方法在Update()方法中调用,这意味着如果我理解正确的话,如果它没有额外的条件,则会重复调用它。 所以基本上我想通过将if (iTrack == 0)放在外面来使for循环只运行一次。

奇怪的是,Debug.Log命令根本不会运行(在控制台中永远不会显示文本"Here 1""Here2" ),但是里面的其他代码如var lerpedPositionwhatToSpawnClone可以运行。

为什么“调试日志”命令不起作用? 我在用这段代码做错什么了吗? 这非常令人困惑。

int iTrack = 0;
int matricesNumber = 2;

public void DrawPoints()
{
    int startIndex = 0;
    int endIndex = mesh.vertexCount;

    float t = Mathf.Clamp((Time.time % 2f) / 2f, 0f, 1f);

    if (iTrack == 0) { 
        if (matricesNumber == 2)
        {
            for (int i = startIndex; i < endIndex; i++)
            {
                Debug.Log("Here 1");

                var lerpedPosition = Vector3.Lerp(matrices1[i].position, matrices2[i].position, t);
                whatToSpawnClone = Instantiate(whatToSpawnPrefab, lerpedPosition, matrices2[i].rotation) as GameObject;

                if (i == (endIndex - 1))
                {
                    Debug.Log("Here 2");
                    iTrack = 1;
                }
            }           
        }
    }
}

基于对问题的描述,我将假设您从现在开始为Unity创建脚本。 看看这个 它提供了两个值得一试的解决方案,主要是第二个解决方案,因为它非常简单,只需检查一下即可确保为控制台启用了Debug输出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM