Hello everyone I want to try write fps tutorial with c# instead of JavaScript,but i run into some problems. First,I want to know that how can I define a local variable in a method?Like a variable for defining Rigidbody types in Update method. After that,I want to ask you to give me some codes with c# in FPS Tutorial because I am so tired of converting java script codes to c# it would be highly appreciated if you answer me soon
this should help you with converting
most people won't write code for you
if you have a specific question/problem you can't find an answer for after at least a minimum searching you can ask and anyone 'll gladly help
to answer your question?..
void Update () {
Rigidbody a_rigidbody;
// `typename` `variablename`
}
Converting js to mono is actually fairly straightforward. See Matyi Csapo's reference for more.
function local variables would be defined the same way in either language:
js
function Update() {
var foo : int = 0;
//do something with foo
}
mono (Bar.cs)
using UnityEngine;
public class Bar : MonoBehaviour {
void Update () {
int foo = 0;
//do something with foo
}
}
Rigidbody types? I'm not sure I get your meaning. there either is or is not a Rigidbody. If you were defining your own class which derives from Rigidbody, it would be done much the same in either language. You could create a Rigidbody with `Rigidbody foo = new Rigidbody();`, but that doesn't really change the type in any way. If you're referring to the rigidbody local to all components, you would access it the same way in wither language `rigidbody.AddForce(x);`
Asking someone to write your code for you because you're lazy is likely not going to yield much return. Why should they? The script is not that long and shouldn't take very long to convert at all.