Join Kelley Hecker for an in-depth discussion in this video Defining classes and variables, part of Scripting Unity with C#.
- Each script you create will be its own class,…with the class name matching the file name.…To create a new C# script,…right click in the project window and select…create C# script.…Since the script's file name is the same as the class name,…all your script files must have unique names.…Double click the script to open it in MonoDevelop.…You can see it already has a basic class implementation…along with start and update functions,…which we'll talk more about later.…
Variables are defined by specifying the access modifier…public, private, or protected,…the type of the object, and the variable name.…If you don't specify the access modifier,…it will default to private.…Since C# is statically typed,…you have to specify the type of the object here.…I like to place class member variables…at the top of the class, before any of the functions.…You can see how functions are defined by looking…at the start and update functions.…
Just like defining a variable, you can specify…an access modifier,…or leave it blank to default to private.…
- 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
Advanced Unity 3D Game Programmingwith Michael House3h 45m Advanced
Creating Mobile Games with Unitywith Kelley Hecker1h 12m Intermediate
1. Your First Script
3. Built-In Unity Classes
Picking up coins4m 8s
5. Events and Delegates
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take 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.