Join Kelley Hecker for an in-depth discussion in this video Attaching a script, part of Scripting Unity with C#.
- In most cases you'll be attaching your…script to a GameObject in your scene.…The easiest way to do this is to…find your script in the project window…and click and drag it onto an object in the Hierarchy.…Another way to add a script is to click on the GameObject…and in the Inspector click Add Component.…Then find and click on the script you want to add.…As you can see a GameObject can have…multiple instances of the same script.…You can also add a script by going…to the Component menu, Scripts,…and clicking on the script that you want to add.…
Either of these methods also lets you…add a script to multiple objects at a time.…If I create some more GameObjects,…and select them all by holding down shift,…I can click on Add Component in the Inspector,…and add my script to all of them at once.…You can remove a script from an object…by clicking on the gear icon next to the script name…and selecting Remove Component.…
You can also reorder your scripts…by using the Move Up and Move Down commands.…You can even copy a script…
- Defining classes and variables
- Attaching scripts to objects
- Understanding MonoBehaviour class
- Using the Unity Scripting API
- Importing assets
- Using a singleton pattern to manage game state
- Creating an event
Skill Level Intermediate
Q: Why am I getting a script compile error when trying to load the exercise files?
A: This course was recorded in Unity 4.6, and Unity has since released Unity 5. There are two items to address for Unity 5 users.
Q: Why can't I see the Render Settings option in the Edit menu?
A: The Render Settings options have been moved in Unity 5. You can access them by going to the Window menu and choosing Lighting. In the window that loads, Render Settings can be found under the Scene tab.