[英]Why doesn't Debug.Log work in this for loop?
這就是我所擁有的。 此DrawPoints()方法在Update()方法中調用,這意味着如果我理解正確的話,如果它沒有額外的條件,則會重復調用它。 所以基本上我想通過將if (iTrack == 0)
放在外面來使for循環只運行一次。
奇怪的是,Debug.Log命令根本不會運行(在控制台中永遠不會顯示文本"Here 1"
或"Here2"
),但是里面的其他代碼如var lerpedPosition
和whatToSpawnClone
可以運行。
為什么“調試日志”命令不起作用? 我在用這段代碼做錯什么了嗎? 這非常令人困惑。
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.