Search Unity

Should I rewatch the scripting tutorials for C#?

Discussion in 'Scripting' started by SassMaster, Sep 20, 2014.

  1. SassMaster

    SassMaster

    Joined:
    Sep 16, 2014
    Posts:
    8
    Here's the deal. I've spent a fair bit of time doing stuff in Java and Javascript, and I've done a couple of Unity games in JS, but now that I've started learning C# for non Unity purposes, I decided to use it in Unity. As soon as I tried to get into the actual scripting part of making a game, I realized that nothing works quite how I want it to, and many features and code blocks that I thought would work just throw errors at me.

    It feels like I'm not progressing, and I'm wondering if it's just that Unity C# is completely different to Unity's JS, and if I should redo all the tutorials I watched for Unity that showed all the Syntax and how to use the API, or if I just need to take a look at how syntax works in Unity's C#.
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Really? Unity's C# is just... C#. They performed no change on it, unlike UnityScript which is not quite like JavaScript.

    Converting code from US to C# usually tends to be straight forwards. Can you post more specific issue?
     
  3. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    C# is the same as unity script. Just slightly different syntax.

    They both reference the same classes within unity, MonoBehavior, UnityEngine, etc. So same functions, same parameters, etc.

    It sounds like you just need to become familiar with some of the basics of how c# is different to javascipt.
     
  4. SassMaster

    SassMaster

    Joined:
    Sep 16, 2014
    Posts:
    8
    That's what I was wondering. If I just need to learn how to apply what I already know into C# or if I need to go over all of the tutorials again.

    Do you have any links that could help with the switch from JS to C#?
     
  5. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    there's only slight differences between unity JS and unity C#, you can reference the Unity Docs (help menu -> script reference). Type in the function you're interested in into the search, or select what you need from the tree on the left. There's a switch on the top right (boo, js, C#), select the language you wish to see the examples in. While some examples aren't in every language, a lot if them are, or don't need to be. Hope this helps! :)
     
    hippocoder likes this.
  6. SassMaster

    SassMaster

    Joined:
    Sep 16, 2014
    Posts:
    8
    Unity's C# is C#, but if I went ahead and programmed like normal, using .NET framework functions and programming for console applications, Unity would refuse it instantly. Unity had it's own API, and I thought that after learning how to use said API in JS, I could use it in C# with no problems, but it seems like the API is used differently in C# than it is in JS.
     
  7. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
  8. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    No disrespect SassMaster, but from reading your comments you don't sound like you have much experience. Therefore doing the C# tutorials is probably a good idea so that you learn good habits. Otherwise you might develop bad habits if you try to work things out yourself.

    As you point out, c# is c#, this correct but only for the syntax, your coding environment determines what tools you can access. In your original post you mention you are using C# for non-unity purposes. You are probably using .net framework 4.0 or 4.5. There is a lot of new stuff in these frame works that is not available in Unity. That is because Unity uses .net framework 2.0 (the Mono version of it at least). The other big difference is the namespace inclusions, (the using statements at the top of your C# code), in unity you are using UnityEngine. For your non-unity staff you are probably using winforms or asp and so you will be using the microsoft system inclusions. These determine what functions and object types are available, in these areas Unity and your other stuff are worlds apart. This does not mean c# isn't c#, it just changes what objects and functions you can use.

    C# is the language. Like English, it is a language. A Physicist and a Lawyer both speak English, but that does not mean a Physicist can practice law or a Lawyer can unlock the secrets of the universe, they operate in different fields of knowledge. The same is true for using C# in Unity and in another environment.

    (Apologies, I think I am getting a bit too preachy)
     
    Last edited: Sep 20, 2014
    ThermalFusion likes this.
  9. SassMaster

    SassMaster

    Joined:
    Sep 16, 2014
    Posts:
    8
    That's exactly what I mean. I don't have much experience with Unity, but I am experienced with programming, and I know C# is C#, but to make Unity do what you want it to do, you have to use it's API. If I typed something about "Transform.Translate(GameObject) //Something or other," into an IDE for a console application, it would reject it instantly, and that's where I'm having trouble. The API for Unity is applied differently in JS than compared to C# and I thought that I would be relatively the same, but now I realize it's not.
     
  10. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    If you typed Transform.translate into C# for a console app it would only complain that the Transform class is non existent. Language syntax is the same for C# regardless of if you're working with unity, a console app or a other framework.

    You just need to learn the unity API which documented very well, and is also the same api reguradless of if your using C# or UnityScript or even boo.