Components in Unity

Treehouse

Course Summary

Every GameObject in Unity can use components, which are pieces of code that can change how the game behaves. We'll explore some of the problems that can surface while programming and techniques you can use to untangle your thinking.

+

Course Description

About this Course Every GameObject in Unity can use components, which are pieces of code that can change how the game behaves. We'll explore some of the problems that can surface while programming and techniques you can use to untangle your thinking. What you'll learn

Methods

Components

Code Architecture

About the TeacherNick is a teacher at Treehouse and an independent game developer. His Twitter handle is @nickrp.

+

Course Description

About this Course Every GameObject in Unity can use components, which are pieces of code that can change how the game behaves. We'll explore some of the problems that can surface while programming and techniques you can use to untangle your thinking. What you'll learn

Methods

Components

Code Architecture

About the TeacherNick is a teacher at Treehouse and an independent game developer. His Twitter handle is @nickrp.

+

Course Syllabus

Organizing Code into Methods

It's a lot harder to build on top of a mess than it is to build on a stable foundation. We'll learn how to take an existing Unity project with messy scripts and organize them into scripts that utilize methods. 5 steps

Project Overview 4:07

Spaghetti Code 5:46

Organizing GameManager into Methods 8:15

Organizing ShootArrow into Methods 4:16

Organizing Code into Methods 5 questions

Extra Credit Feeling adventurous? Try going back to one of your previous Unity projects and look for code in the Update() method that could be reorganized into smaller methods.

Thinking in Components

Writing methods is a good start, but we can go a step further by segmenting each unique piece of behavior into a new script, and, a new component. By creating individual components that serve a clear singular purpose, we can start to build a library of reusable code. 4 steps

The Entity Component Pattern 6:09

Organizing Code into Components 4:31

Building the Target Spawner 11:31

Thinking in Components 5 questions

Extra Credit Think you can do better? Try examining other parts of the project and look for places where scripts can be made into reusable components.

Adding New Behavior

Now that we've organized our code into methods and components, we're ready to start building new behavior. The true test of code quality is how easy it is to change later on, so let's try to add some new features. 3 steps

Creating a New Component 8:46

Integrating New Components 7:49

Adding New Behavior 5 questions

Extra Credit In addition to targets that move left and right, try adding additional target types. Why types of features can you come up with?