foreach (GameObject target in targets)
{
objCount ;
Animator targetAnimator = targets.GetComponent<Animator>();
if (targetAnimator.GetInteger("Hit") == 1)
{
hitTargets ;
}
}
錯誤:CS1579 foreach 陳述句無法對“GameObject”型別的變數進行操作,因為“GameObject”不包含“GetEnumerator”的公共實體或擴展定義
uj5u.com熱心網友回復:
因為foreach是實作迭代器模式的糖語法讓我們使用簡單的迭代器,
IEnumerable如果你想在需要實作介面的串列或集合中使用它foreach
根據您的錯誤,targets如果未實作IEnumerable介面(GameObject) ,則無法在 foreach 中使用
也許你可以使用
objCount ;
Animator targetAnimator = targets.GetComponent<Animator>();
if (targetAnimator.GetInteger("Hit") == 1)
{
hitTargets ;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/462717.html
上一篇:LINQ查詢引發客戶端評估錯誤
