- Home /
Foreach Error
Im using this code example from the unity script reference but as is there is a error and I can't tell why I get this error
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html // C# version
foreach statement cannot operate on variables of type 'UnityEngine.Object' because 'UnityEngine.Object' does not contain a public definition for 'GetEnumerator'
my code:
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour {
public GameObject invslot;
public Object invslots;
void Awake()
{
itm = GameObject.Find("FPSPlayer").GetComponent<Item>();
uss = GetComponent<UISlicedSprite>();
//AddStuff();
}
public void CheckPanelChildren()
{
if (invslots == null)
GameObject.FindGameObjectsWithTag("Invslot");
foreach (Object c in invslots) // error right here
{
}
}
}
Answer by cj31387 · Mar 23, 2013 at 11:59 PM
Figured it out. In the script reference for C# it should be an array.
public Object respawns; should be public Object[] respawns;
Your answer

Follow this Question
Related Questions
Targeting Issue Error 1 Answer
Multiple Cars not working 1 Answer
Error assigning to a variable 0 Answers
Distribute terrain in zones 3 Answers
Error assigning to a variable 0 Answers