foreach (GameObject target in targets)
{
objCount++;
Animator targetAnimator = targets.GetComponent<Animator>();
if (targetAnimator.GetInteger("Hit") == 1)
{
hitTargets++;
}
}
错误:CS1579 foreach 语句无法对“GameObject”类型的变量进行操作,因为“GameObject”不包含“GetEnumerator”的公共实例或扩展定义
因为foreach
是实现迭代器模式的糖语法,所以让我们使用简单的迭代器一个列表或集合,IEnumerable
如果你想在其中使用它需要实现接口foreach
根据您的错误,targets
如果未实现IEnumerable
接口(GameObject
) ,则无法在 foreach 中使用
也许你可以使用
objCount++;
Animator targetAnimator = targets.GetComponent<Animator>();
if (targetAnimator.GetInteger("Hit") == 1)
{
hitTargets++;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句