Book Image

Learning Unity iOS Game Development

Book Image

Learning Unity iOS Game Development

Overview of this book

Table of Contents (14 chapters)
Learning Unity iOS Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
6
Main Menu, iAds, Leaderboards, Store Purchases, and Achievements
Index

Adding Box Collider 2D


The Box Collider 2D component will give our character a bounding box that will interact with the world around it. This means that if the character hits another GameObject that also has Collider, we will be able to use code to know about it. This is imperative to the interaction of the character with the game world since without it, we wouldn't have the information needed to do things, such as collect pick-ups, or know when the character hit something dangerous, such as the obstacles.

Just as Rigidbody 2D, the Box Collider 2D component is easy to set up.

  1. With the Character GameObject selected, navigate to the Inspector tab and click on Add Component.

  2. Search for Box Collider 2D and select Box Collider 2D.

By default, Box Collider 2D will fit itself around the image. As our image is 32 x 32 pixels wide and high by default, the collider will match it as it is also 32 x 32 pixels wide and high. To make it fit our character better, change the X value of Size down to 0.22:

This...