- Home /
Casting objects in Unity using a local class of an object
I know it sounds weird, but I have this situation going on. psuedo/simplified code, in essence, I'm trying to be able to access data/variables from "foo"'s "inner foo" class from "bar."
public class foo
{
ArrayList pass;
public class innerFoo
{
//stuff in here
}
void start()
{
pass = new ArrayList();
pass.Add(new innerfoo());
}
}
public class bar
{
public gameObjectWithFoo O;
void start()
{
ArrayList LIST = new ArrayList();
LIST.add(O.pass[0]);
//
//Here is where I'm stuck, How would I cast LIST[0] as the innerfoo type, the ArrayList<ObjectType> syntax isn't working either...
//
}
}
Comment
Answer by Jamora · Feb 26, 2014 at 06:24 PM
In C# you can just create a list of the specific type:
List< foo.innerFoo> pass = new List< foo.innerFoo >();
You don't now need to cast anything; pass[0]
returns a type of foo.innerFoo
.