Creating a Component

Just as for assets and GameObjects, we have a couple of ways of adding a Component to a GameObject (remember that we must create our GameObject first). Click the Component menu and then select from one of the submenus available. This will assign the selected Component to the currently selected GameObject. We can also do the same thing by clicking the Add Component button inside the Inspector with our GameObject selected.

Another method is to drag and drop an asset into the Hierarchy window or Scene View. Unity will automatically define which type of GameObject and Component this should be according to its Import Settings. While this method is available, we suggest creating Components from the menu or inside the Inspector ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.