- Home /
Is Unity Intermediate Scripting tutorials still revelant to UnityScript users ?
I am trying to follow those tutorials (http://unity3d.com/learn/tutorials/modules/intermediate/scripting), but I find myself thinking if it was only made for C# users ?
What I mean is, does this tutorial only apply for C# users since it is teaching OOP ? I found myself trying the Inheritance tutorial in javascript and I was greeted with several errors and warnings.
First, creating a class without derivating from Monobehaviour in javascript is not possible, but in the tutorial it was. I got an error saying that my class needed to derivate from MonoBehaviour or else Scriptable object.
Second, the "new" keyword when instancing a derivated class apply also for a C# usage. It will work for Javascript, but I get a warning message telling me to use instead AddComponent.
Third, the tutorial don't tell me how to make it work in Unity Editor. Do I need to only attach the FruitSalad class to an object, or do I need also the Fruit and Apple Class to be also attached to that game object.
What do you think ? Is OOP still be possible in javascript with these tutorials ? If not, what could be the right piece of code I should use if I want to program OOP javascript for that tutorial ?
Answer by JamesB · Aug 19, 2013 at 11:11 AM
The intermediate scripting tutorials are more focused on C# at the moment, but not all of the lessons will apply to C# only. As you progress in game development it becomes more important to know more of the features of the language that you use. As the examples from the tutorials show, features like inheritance can be very powerful in helping you create games. Unfortunately we simply don't have the time to cover everything in every language. As such we had to choose the language that would make everything that each script was doing as clear and plain as possible. Since there is a lot that is hidden in javascript (for example the implicit class declarations) we went with C#. In order to make a javascript not inherit from monobehaviour you need to make an explicit class declaration.
I'm not sure, but it sounds like you might be a little confused over the use of classes in Unity. All scripts that are attached to gameobjects are monobehaviours. This means that they inherit from the monobehaviour class. This is quite obvious (once you know about inheritance) in C# since you can see : MonoBehaviour at the top of every class declaration. However, in JS, since the declaration is implicit this isn't as obvious. If you try to create a "new" instance of a monobehaviour then you will get the error that you mentioned.
My honest advice in this situation would be to have a go at C#. That may seem daunting or unpleasant (you've already spent the effort learning JS, so why should you bother?) but it will be worthwhile in the long run. Having already learnt JS, you're more than halfway there! Before intermediate scripting, the differences are pretty much just variable and function declarations. They are all summarised in the beginner scripting lesson comparing the two languages.
Again, this may sound like a lot of effort, but it's less than you think and it will be worth while in the long run. Think of how much more powerful your games can be with all the OOP tools working for you!
I hope this helps.
Hi ! Thanks for the advice. You answered well my concerns, but I was also wondering why the javascript/Boo conterpart of that tutorial was available also for users? It confused me in a sense, because I thought it would be possible to do OOP with unityScript but in a sense the tutorial applies more to C#. Do you know why ?
Later on in intermediate scripting and advanced scripting, there will be some concepts and practices that will be based on things learnt for the language at these earlier stages. We would love to try and do tutorials in js and boo too, but we simply don't have the time. Ins$$anonymous$$d, we'd prefer to make tutorials in C# and translate them as best we can. Sometimes things don't translate at all in which case we put a comment to that effect. Otherwise we will try to translate it into js and boo so that it most closely fits C#.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112516im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get AI ( Boots ) 1 Answer
Need some pointers towards basics. 0 Answers
Can anyone give the help me with the full Movearound.javascript? 0 Answers
Tutorials Don't work. 1 Answer
Space Shooter Tutorial Lessons 2 Answers