From the course: Learning Unity 2D Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adding new scripts

Adding new scripts - Unity Tutorial

From the course: Learning Unity 2D Scripting

Start my 1-month free trial

Adding new scripts

- [Narrator] At this point, we've looked at some examples of how the MonoBehaviour works, and how to expose even more fields to the inspector. But one of the things that Unity stresses over other game engines, is composition versus inheritance. Inheritance is when we directly extend another class and get all of its functionality. If we look at our code, the best example of this is that our HelloWorld script directly extends MonoBehaviour. The fact that we're able to use awake and start, and update are all benefits of extending MonoBehaviour. But, you don't always want to keep extending class after class after class. Composition is what allows us to create separate classes and use them together as one system. In the case of Unity, each of the components on a game object can act as independent blocks of logic that manages specific subsystem of a given game object. This means we can have one script that manages the data of our game object, we can have another that manages the movement…

Contents