C# CharacterCotnroller syntax?

I’ve been converting some example projects I found from js to C#. I have two questions that perhaps someone can illuminate for me…

  1. I’m trying to convert the following lines to C#.
CharacterController controller = GetComponent(CharacterController); 
controller.Move(moveDirection * Time.deltaTime);

When declaring it, I get the following errors:
" Expression denotes a type', where a variable’, value' or method group’ was expected". I thought CharacterController was a Component, and therefore the following would work.

Component controller = GetComponent("CharacterController");

But while it accepts that syntax, it complains that UnityEngine.Component doesn’t contain a definition for Move.

  1. Can anyone point me to Unity 3D C# code examples (I’ve seen the 3 or 4 that comes with the Standard Assets- but not much else on the interweb)? It’d be kind of like a “Rosetta stone” of sorts. :slight_smile:

Here ya go;

CharacterController myController = GetComponent(typeof(CharacterController)) as CharacterController;

To understand what’s going on here;

You want to get the component “type”, hence the “typeof” call. You could also just name the component type as a string, but either way you need to cast, or translate the return value from a generic Component into a specfic type (CharacterController) hence the “as CharacterController”.

Ah yes- I attempted “typeof” before, but “as CharacterController” makes sense.

Much appreciated!