Simple Questions !

Hi my friends 8)
I am a newer in Unity (Of course not newer in programming)
I havae some questions.
How I can to learn Unity Script very well ?
Is there any script tutorial ?

I write this simple code in c# (Visual Studio) but doesn’t work !!

GetComponent(Transform).Translate(0, 1, 0);

Why doesn’t work ?!!

(I studied Unity scripting manual and this code is into manual)

Please help me :lol:

Hi 3Dmajid,

I’m coding In C# as well.

There will a couple of things that you will have to figure out how to do.

for example:

this will NOT work in C# (even though it works in Javascript)

transform.position.y += 0.75f;

But this WILL work;

float yPos = 0.75f + transform.position.y;
transform.position = new Vector3(transform.position.x, yPos, transform.position.z);

In the case of GetComponents and anything related to that for that matter, you will have to change a bit the syntax.

Here are a couple of examples that are self explanatory.

when you want to get the character controller…

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

***note for this code: replace “GameObject” by the name that you are using in your code…

Component[] goChild = GameObject.GetComponentsInChildren(typeof(Transform));

When using floats, make it a habit of writing them properly like in the following example. It’s less confusing when it compiles and also it’s easier to differentiate your floats from your double and even your integers.

Vector3 movement = moveDirection * moveSpeed + new Vector3(0.0f, verticalSpeed, 0.0f) + inAirVelocity;
[RequireComponent(typeof(CharacterController))]
[AddComponentMenu("Third Person Player/Third Person Controller")]

Also When searching the forum, I normally do it through Google by using the first two keywords; unity and c#. Then I add whatever I want to look for and normally I can find it. Otherwise, I have to figure it out and I’m glad to say that I almost always do. :smile:

One last thing, I normally “translate” code from JavaScript to C#. Sometimes in the code, there will be a variable that is equal to something but the variable is not identified in JavaScript so that when you compile in c#, you will get an error. Just go to the line where you have your error and put your mouse cursor on what the variable is equal to to see what type of variable you have to generate and everything will be ok. Also, don’t mix while loops with the update function, it will hang Unity and yield needs to be coded in a special way. see link for example for the StartCoroutine function;

http://answers.unity3d.com/questions/12410/c-while-loop-question

Other then that, it’s pretty much straight forward to go from one language to the other.

So I hope this clears things out for you.

A wolrd thanx my friend :sweat_smile:

Is there a good editor for write Java codes in unity ?

I don’t code in JavaScript but the one I use to visualize JavaScript code is UniScite

But go to this link and you will be able to find alot of answers to your questions regarding tools, editors and others to use with Unity.