Before updating to Windows 10 you may need to return your Pro license. More information here

Character Controller in C#

I got problems when trying to access Character controller from C# file but the same theory on Javascript works.

C# CharacterController controller = GetComponent(CharacterController);

JavaScript var controller : CharacterController = GetComponent(CharacterController);

Can anyone help me how can I access the character controller from C#...

The errorss I am getting is "Expression denotes a type, where a varuable, value or method group was expected."

more ▼

asked Aug 22, 2010 at 02:28 PM

avatar image

Thet Naing Swe
881 184 162 149

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

What Matyi Csapo offered will work. I prefer not so many glyphs on my screen, so I use the generic version:

CharacterController controller = GetComponent<CharacterController>();

You'll find this right on the documentation page. (It is missing a semicolon, but this page has been rewritten for the 3.0 documentation and looks error-free there.)

more ▼

answered Aug 22, 2010 at 02:44 PM

avatar image

19.1k 212 203 317

didn't know of this but it sure is cleaner so thanks :D

Aug 22, 2010 at 04:03 PM matyicsapo

woa woa woa what's wrong with this?

bunch of links are missing?

Sep 14, 2013 at 10:00 AM sdgd
(comments are locked)
10|3000 characters needed characters left

CharacterController controller = (CharacterController)GetComponent(typeof(CharacterController));


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

more ▼

answered Aug 22, 2010 at 02:36 PM

avatar image

674 34 27 44


CharacterController controller = GetComponent("CharacterController") as CharacterController;

just remembered

Sep 14, 2013 at 10:07 AM sdgd
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Aug 22, 2010 at 02:28 PM

Seen: 16799 times

Last Updated: Sep 14, 2013 at 10:08 AM