In Unity, scripting provides a powerful tool set to extend and enhance the functionality of the game. We can even extend and enhance the functionality of Unity itself. And it supports three different scripting languages plus a shader language to do so. To attach a script to a game object, like we did with the first person controller, we can simply drag it in as a component. I'll put a new blank script on one of my objects to start out. For example, I'll pick the master building and add a component. In the Components, I'll choose New Script.
And I've got some different languages available. Unity supports JavaScript, C sharp, and Boo, which is a Python variant. I'll choose JavaScript, for example, and name this new script, sink. Now I have got a new script on this game object master building. The new script is noted with a JS icon next to the name Sink. And that shows that it's a JavaScript. The script then is chosen called Sink. And if I add any other functionality it will show up there. We can edit this script then in MonoDevelop, either double-clicking on it in the assets folder or dropping down here under the gear and choosing Edit Script.
MonoDevelop is a powerful scripting program that ships with unity and supports multiple languages. It also supports code hinting and syntax coloring. It will help you along as much as it can and really let you get in and get the best out of your scripting. What this says, for example now, is that when the game starts, function start, do something. In this case nothing. And then update every frame, do something and again, nothing. We're ready to add pieces into this script and it's that simple to attach scripts to an object.
We can either make scripts by choosing new components or we can make a new script right in the assets window and then drag it onto an object. I'll close this script sink in MonoDevelop and come back and look at creating a new script. I'll right click in the Assets window, and choose Create. And here's a C sharp. I'll name this C sharp, rise. And there's that C sharp script selected in the inspector, showing, well, what's going on so far. In this case, void start, nothing, and void update, nothing.
When it starts out the game, initializes, do something and once per frame, do something. That's the basics of it. We can make a script to do just about anything we'd like. Anything from culling animations through extending functionality when a character collides with something If you've used a first-person controller, you're already using scripts. And it's that simple to get them implemented. There's no limit to what you can do with the script. So get in and explore. And start to make scripts that enhance the functionality of your game.
Author
Released
3/10/2014- Designing the game
- Creating and transforming objects
- Importing and configuring models and textures
- Setting properties in the Inspector
- Creating the terrain geometry
- Building materials and adding shaders
- Creating GameObjects
- Exploring physics
- Animating objects
- Lighting the scene
- Creating 2D game elements
- Adding special effects
Skill Level Beginner
Duration
Views
Related Courses
-
Unity: Materials and Lighting
with Adam Crespi2h 20m Intermediate
-
1. Introduction
-
Welcome38s
-
Using the exercise files1m 24s
-
-
2. Navigating the Interface
-
Designing the game4m 39s
-
Setting the project4m 9s
-
-
3. Working with Imported Assets
-
Organizing the Assets window2m 55s
-
-
4. Creating the Game Environment
-
Publishing project settings5m 32s
-
Adding sky and fog8m 17s
-
5. Creating Terrain
-
Forming the topography9m 53s
-
Painting trees and forests10m 55s
-
Painting detail meshes8m 45s
-
Adjusting terrain settings7m 34s
-
6. Materials and Shaders
-
Handling multiple materials7m 13s
-
Manipulating textures5m 20s
-
Creating lit materials6m 18s
-
7. Working with GameObjects and Components
-
Creating GameObjects5m 2s
-
Understanding components6m 15s
-
Using colliders for barriers6m 22s
-
Exploring physics8m 22s
-
-
8. Keyframing Animation
-
Animating an object6m 32s
-
9. Animating Skinned Meshes and Controlling Characters in Mecanim
-
Importing skinned meshes4m 51s
-
-
10. Lighting the Scene
-
Customizing ambient light2m 59s
-
Adding spot and point lights4m 25s
-
Using point lights for fill4m 30s
-
-
11. Introducing Unity Scripting
-
Using correct script syntax6m 33s
-
12. Creating 2D Game Elements
-
Setting up a 2D project3m 13s
-
Importing sprites2m 30s
-
Creating 2D colliders3m 12s
-
Adding 2D physics2m 25s
-
Animating 2D elements3m 29s
-
-
13. Adding Image Effects
-
Adding depth of field8m 40s
-
Applying motion blur5m 46s
-
Tuning color for mood6m 2s
-
14. Adding Special Effects and Audio
-
Exploring water effects7m 35s
-
Working with wind zones2m 8s
-
Using an audio source4m 3s
-
Creating a sound zone5m 58s
-
Triggering audio3m 37s
-
Adding audio effects3m 13s
-
Creating particle systems2m 25s
-
Adjusting particle systems9m 14s
-
-
15. Building the Game
-
Setting up occlusion culling5m 52s
-
Building the executable5m 36s
-
-
16. Conclusion
-
Next steps49s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Adding scripts to GameObjects