Components
Time 2.9 hrs

Difficulty Intermediate
Prerequisites Instantiation
Departments Science
Authors Sandra Kuipers
Groupings Individual
Pairs
Minimum Year Group None

Blurb

Components

License

This work is shared under the following license: Creative Commons BY-SA-NC

Outline

Learner Outcomes
Students will:
  • ...
Competency Focus
  • ...
Interdisciplinary Connections
  • ...
Reflection
What was successful? What needs changing? Alternative Assessments and Lesson Ideas? What other Differentiation Ideas/Plans could be used?
  • ...
Credits
Any CC attribution, thanks, credit, etc.

This page requires you to be logged in to access it. Please login and try again.
5 mins
Unity Components
Introduction
  • Components are the basic building block in Unity.
  • Every script is, by default, a component.
  • Using components, we can build up more and more complex logic.
  • In this unit, we'll look at what components are, and how components interact with each other.
10 mins
The Component Model
Theory

  • Unity uses a software architecture called Component-based Architecture.
  • Component architecture is useful for:
    • Re-usability - create a component for each game behavior, and use it in many different places.
    • Fast development - compose new object behaviors by combining existing components.
    • Collaboration - programmers can create the components that designers use to create scenes.
5 mins
Game Objects
The Basics

  • A GameObject is a blank-slate.
  • Every object is built by adding components to your GameObjects.
    • Your player is a GameObject.
    • Your scene in made up of GameObjects.
    • Your user interface is also GameObjects.
    • Each object simply has different components.
  • This type of architecture uses composition to create unique behaviour.

  • By default, every GameObject has a transform component.
  • This component controls the object's position in the game scene.
  • Other built-in components can be added, such as colliders and render meshes.
  • You can also create your own components by writing a script and adding it to the object.
  • Check out the docs for some great resources:
10 mins
Accessing Components
Digging In
  • To create complex behaviour, you'll need to access one component from inside another component.
  • For example, if a player is damaged in a game, the player object may need to communicate with the UI to display the current player health.
  • Communicating between objects is done by accessing the component of another object.
    • This can be done by pre-defining a variable and connecting it before the game starts.
    • Or, you can use the GetComponent() method to access a component during run-time.

10 mins
Broadcasting Messages
Digging In
  • Another way to communicate between components is the SendMessage() or BroadcastMessage() methods.
  • SendMessage() These lets you call a method on every other component in the same GameObject.
  • BroadcastMessage() is similar, but also calls the method on any children of the GameObject.

  • Messages are handy because you don't need to know who the receiver is.
  • You can send a message, and any other object able to run the method you've called will receive it.
5 mins
Managing Communication
Resources

  • Communicating between components is essential.
  • As your projects become more complex, you may need a central object to facilitate communication.
  • These are often called Game Manager scripts (or Game Controller).
    • A manager script is an invisible object in your game.
    • It connects different parts of your game to communicate important events.
    • You might have a player manager, an enemy manager, an audio manager, and more.
    • Manage scripts are often wired-up with variables that connect to other managers.
10 mins
More Resources
Useful Links
  • To complete this unit, you may need some additional tutorials and resources.
  • The following tutorials can help get you started.
  • Be sure to search for more docs and tutorials as you go.

120 mins
Your Tic-Tac-Toe Game
Evidence
  • Tic-tac-toe is a game of placing Xs and Os to be the first to complete three-in-a-row.
  • Can you program a tic-tac-toe game in Unity?
  • It seems like a simple game on the surface, but it'll require some complex logic.

  • The game will need a few basic elements:
    • A background providing a backdrop for the the entire game.
    • An element that will be our game board.
    • An element, or set of elements, that breaks the game board up into nine areas in an even grid.
    • Nine tiles that can be assigned either an "X" or and "O", but once assigned these values will persist and not be changeable by the players - either the current player or the opponent.
    • Logic to change sides when a player takes their turn.
    • Logic to check for a "Win" condition, allowing for draws where no one wins.
    • A panel that displays who is the winner when the game is over.
  • For polish, you could add some other helpful elements:
    • A way to choose the starting player's side, "X" or "O".
    • An indicator of whose turn it is.
    • A restart button.
    • Very basic instructions.
  • Feel free to grab some graph paper or create a flow chart to help plan out the logic of your game.
  • If you prefer to follow instructions, there is a complete tutorial for creating a tic-tac-toe game.
  • However, you're also welcome to challenge yourself to create this game from scratch!
  • Once you've programmed and tested your tic-tac-toe game, upload the project to Drive and share a link to the project folder as evidence of your learning in this unit.
There are no records to display.
Powered by Gibbon v27.0.00dev

Founded by Ross Parker at ICHK Secondary | Built by Ross Parker, Sandra Kuipers and the Gibbon community
Copyright © Gibbon Foundation 2010-2024 | Gibbon™ of Gibbon Education Ltd. (Hong Kong)
Created under the GNU GPL | Credits | Translators | Support