Using GetComponent in C#...

Hey guys, I am having issues using GetComponent in C#

//temp is a gameobject I create earlier

Collider col = temp.GetComponent(Collider);

The error that line throws is: Expression denotes a “type” where a “variable” or “method group” was expected.

I am using it just as it said in the docs…so what am I missing?

Thanks guys,
-Jeremy

Argh... I ended up finding this in some code on the wiki:

temp.GetComponent(typeof(Collider)) as Collider;

I would really think this usage sould be on the docs somewhere as it just says: GetComponent(Collider) in the docs. But maybe it's just me... :shock:

-Jeremy

It’s not you or the docs, it is C#.

Yeah, I do understand that, but it wasn’t clear that you even had to do that to pass what the unity function needed.

-Jeremy

Heh, on a related note, anyone know a good C# book?

Thanks,
-Jeremy

I liked this one.

Thanks Neil, I will check it out.

-Jeremy