- Home /
3rd person controller in c#?
Hi, I have been using unity's 3rd person character controller and camera controller. I am however having some issues with IEnumerators and coroutines. I am learning C# and this script is written in javascript. I can use IEnumerators and coroutines fine in C# but I don't know how to use them properly in JS.
Is there anywhere I can get the exact same character controller/camera controller scripts in C#? I have looked everywhere and so far only found 1 that had been translated by someone and it didnt seem to work for me.
Thanks a lot
C#
IEnumerator WaitAndPrint(float waitTime) {
yield return new WaitForSeconds(waitTime);
print("WaitAndPrint " + Time.time);
}
JS
function WaitAndPrint (waitTime : float) {
yield WaitForSeconds (waitTime);
print ("WaitAndPrint "+ Time.time);
}
There is not too much difference. Hope this helps. Taken from the official docs.
This is a poorly worded question.
If you are using unity's built in 3rd person character and camera controllers then they shouldn't depend on the program$$anonymous$$g language. Otherwise, if you are using a custom 3rd person character controller then you should share which one. I'm also not sure why you spend the first few sentences discussing IEnumerators and coroutines without discussing how it relates to the controllers.
Answer by maccabbe · Jun 07, 2015 at 10:06 PM
I tried to answer as best I could given the question submitted. Since you submitted this as "3rd person controller in c#?" it originally seemed like the part about IEnumerators and Coroutines had something to do with the 3rd person controller. Based on your response this does not seem to be the case.
If you need help programming in I recommend you follow the unity scripting tutorials which provide examples of both C# and javascript syntax
https://unity3d.com/learn/tutorials/modules/beginner/scripting
For instance the following has a video of how to use coroutines along with 3 different examples in both languages, just click on the tabs labeled C# and JS on top of the scripts to chose what language to display.
https://unity3d.com/learn/tutorials/modules/intermediate/scripting/coroutines
Next, Unity's CharacterController (and pretty much everything else built into unity) is not specific to JS. In the scripting API there is a JS and C# tab in the top right which lets you select what language you want to see the syntax for and see the examples.
http://docs.unity3d.com/ScriptReference/CharacterController.Move.html http://docs.unity3d.com/ScriptReference/CharacterController.html