x


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

Thet Naing Swe gravatar image

Thet Naing Swe
826 183 142 144

(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

Jessy gravatar image

Jessy
18.2k 207 174 283

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));

OR

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

more ▼

answered Aug 22, 2010 at 02:36 PM

matyicsapo gravatar image

matyicsapo
659 33 25 40

OR

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

By RSS:

Answers

Answers and Comments

Topics:

x1493
x824
x22

asked: Aug 22, 2010 at 02:28 PM

Seen: 14042 times

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