PokeRwOw
PokeRwOw

Reputation: 599

Translation UnityScript to C#: GetComponent

I'm working to translate a Unity project originally in UnityScript to C#. I already have translated a good part of the project, but I'm confronted with some problems:

characterController = GetComponent(CharacterController);

Throws the error:

'UnityEngine.CharacterController' is a type but is used as a variable.
The overloaded method that best suits 'UnityEngine.Component.GetComponent (string)' 
has invalid arguments

And the second error:

GetComponent.<Animation>().Stop();

Throws the error:

Only a subpoena, call, increment, and decrement, and an expectation of new object expressions 
can be used as instruction.

So It's only errors linked with GetComponent, but in UnityScript it's working fine. How to deal with that in C#?

Upvotes: 1

Views: 156

Answers (1)

Andrea
Andrea

Reputation: 6125

characterController = GetComponent(CharacterController);

Should be called with the generic version, in C#:

characterController = GetComponent<CharacterController>();

Regarding the other line, you have an extra dot in the middle. Should be:

GetComponent<Animation>().Stop();

(not sure if you have to specify also the name of the particular animation to stop).

Upvotes: 2

Related Questions