You are on page 1of 54

Learning C 7 By Developing Games

with Unity 2017 Learn C Programming


by building fun and interactive games
with Unity Third Edition Micael Dagraca
Visit to download the full and correct content document:
https://textbookfull.com/product/learning-c-7-by-developing-games-with-unity-2017-le
arn-c-programming-by-building-fun-and-interactive-games-with-unity-third-edition-mic
ael-dagraca/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Learning C by developing games with Unity 2020 An


enjoyable and intuitive approach to getting started
with C programming and Unity Fifth Edition Harrison
Ferrone
https://textbookfull.com/product/learning-c-by-developing-games-
with-unity-2020-an-enjoyable-and-intuitive-approach-to-getting-
started-with-c-programming-and-unity-fifth-edition-harrison-
ferrone/

Learning C by Developing Games with Unity 5 x Develop


your first interactive 2D platformer game by learning
the fundamentals of C Second Edition Greg Lukosek

https://textbookfull.com/product/learning-c-by-developing-games-
with-unity-5-x-develop-your-first-interactive-2d-platformer-game-
by-learning-the-fundamentals-of-c-second-edition-greg-lukosek/

Learning C by Developing Games with Unity 5 x Develop


your first interactive 2D platformer game by learning
the fundamentals of C Second Edition Greg Lukosek

https://textbookfull.com/product/learning-c-by-developing-games-
with-unity-5-x-develop-your-first-interactive-2d-platformer-game-
by-learning-the-fundamentals-of-c-second-edition-greg-lukosek-2/

Developing 2D Games with Unity: Independent Game


Programming with C# 1st Edition Jared Halpern

https://textbookfull.com/product/developing-2d-games-with-unity-
independent-game-programming-with-c-1st-edition-jared-halpern/
Developing 2D Games with Unity: Independent Game
Programming with C# 1st Edition Jared Halpern

https://textbookfull.com/product/developing-2d-games-with-unity-
independent-game-programming-with-c-1st-edition-jared-halpern-2/

Unity 2020 Virtual Reality Projects Learn VR


development by building immersive applications and
games with Unity 2019 4 and later versions Third
Edition Jonathan Linowes
https://textbookfull.com/product/unity-2020-virtual-reality-
projects-learn-vr-development-by-building-immersive-applications-
and-games-with-unity-2019-4-and-later-versions-third-edition-
jonathan-linowes/

Learning C# programming with Unity 3D Alex Okita

https://textbookfull.com/product/learning-c-programming-with-
unity-3d-alex-okita/

Learning C by Programming Games 2nd Edition Wouter Van


Toll

https://textbookfull.com/product/learning-c-by-programming-
games-2nd-edition-wouter-van-toll/

Hands On Game Development Patterns With Unity 2019


Create Engaging Games by Using Industry Standard Design
Patterns With C 1st Edition David Baron

https://textbookfull.com/product/hands-on-game-development-
patterns-with-unity-2019-create-engaging-games-by-using-industry-
standard-design-patterns-with-c-1st-edition-david-baron/
Learning C# 7 By Developing
Games with Unity 2017
Third Edition

Learn C# Programming by building fun and interactive games


with Unity

Micael DaGraça

Greg Lukosek

BIRMINGHAM - MUMBAI
Learning C# 7 By Developing Games with
Unity 2017
Third Edition
Copyright © 2017 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be caused
directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2013

Second edition: March 2016

Third edition: December 2017

Production reference: 1211217

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78847-892-2

www.packtpub.com
Credits

Author
Copy Editor
Micael DaGraça
Safis Editing
Greg Lukosek

Reviewers Project Coordinator


Predrag Koncar Devanshi Doshi

Commissioning Editor Proofreader


Amarabha Banerjee Safis Editing

Acquisition Editor Indexer


Reshma Raman Pratik Shirodkar

Content Development Editor Graphics


Flavian Vaz Jason Monteiro

Technical Editor Production Coordinator


Ralph Rosario Melwyn Dsa
About the Authors
Micael DaGraça is a game designer and an AR developer living in Porto, Portugal. He has
worked for multiple game studios, contributing to the creation of different indie games and
interactive apps. Micael grew up playing video games, and that passion never went away.
So later on, in his life, he decided to learn how to create games. Without any previous
knowledge in coding or 3D animation, he slowly started creating simple games, learning
more with those experiences each time. When the games began working fine and the
gameplay became enjoyable, he started making plans to publish a game in collaboration
with an old friend. Micael was responsible for the technical aspect of the game, ensuring
that the game worked as planned, while his friend created all the artwork for the game.
Finally, the game was published, and it received some positive feedback from other indie
game developers. Since the game generated some revenue, the decision of becoming a game
designer turned into reality. Today, Micael works for other studios, helping others to
develop their game ideas, He has also integrated into a company that focuses on the
creation of interactive apps for health care and pharmaceutic companies. Even not having
time to keep working on personal projects, he has a few frozen game projects that are still
under development with the help of his friend.

"First and most importantly, I would like to thank my parents; they have always worked so
hard and I know that they sacrificed a lot so I could pursuit my dreams. From the bottom of
my heart I thank you mom and dad. To my sister who has supported me in so many ways, I
thank you for helping me start my career as a game designer; without you, my journey
would be much harder. A warm and fluffy thank you to my girlfriend Marta, who helps me
by keeping me motivated and focused on my work; it's been more than a pleasure sharing
my life with you."
Greg Lukosek was born and raised in the Upper Silesia region of Poland. When he was
about 8 years old, his amazing parents bought him and his brother a Commodore C64. That
was when his love of programming started. He would spend hours writing simple basic
code, and when he couldn't write it on the computer directly, he used a notepad.

Greg completed his mechanical engineering diploma at ZSTiO Meritum–Siemianowice


Slaskie, Poland. He has learned all his programming skills through determination and hard
work at home.

Greg met the love of his life, Kasia, in 2003, which changed his life forever. They both
moved to London in search of adventure and decided to stay there.

He started work as a 3D artist and drifted away from programming for some years. Deep
inside, he still felt the urge to come back to game programming. During his career as a 3D
artist, he discovered Unity and adopted it for an interactive visualizations project. At that
very moment, he started programming again.

His love for programming overcomes his love for 3D graphics. Greg ditched his 3D artist
career and came back to writing code professionally. He is now doing what he really
wanted to do since he was 8 years old–developing games.

These days, Greg lives in a little town called Sandy in the UK with Kasia and their son,
Adam.
About the Reviewer
Predrag Koncar is a game developer/artist and multimedia researcher, active in both visual
arts and computer science. His primary areas of interest are games and combining
technology and art. He likes to spend his free time painting and actively participates in art
shows. Predrag has worked as a technical and creative director for many online projects,
published over 40 online games, participated in the production of several mobile games,
and also reviewed five books by Packt Publishing. He has a strong background in Unity,
C#, Augmented Reality, Maya, and AI and is a member of Mensa and ACM SIGGRAPH.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.

https:/​/​www.​packtpub.​com/​mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.

Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial
process. To help us improve, please leave us an honest review on this book's Amazon page
at https:/​/​www.​amazon.​com/​dp/​1788478924.

If you'd like to join our team of regular reviewers, you can e-mail us at
customerreviews@packtpub.com. We award our regular reviewers with free eBooks and
videos in exchange for their valuable feedback. Help us be relentless in improving our
products!
Table of Contents
Preface 1
Chapter 1: Discovering Your Hidden Scripting Skills and Getting Your
Environment Ready 6
Prerequisite knowledge to use this book 7
Dealing with scriptphobia 7
Downloading Unity 8
Obtaining a free license 9
Teaching behavior to GameObjects 9
Using Unity's documentation 10
The Unity community – asking others for help 13
Working with C# script files 13
Creating a C# script file 14
Introducing the MonoDevelop code editor 14
Opening LearningScript in MonoDevelop 16
The namespace – highlighted in blue 17
Watching for possible gotchas while creating script files in Unity 17
Fixing synchronization if it isn't working properly 19
Adding our script to GameObject 19
Lots of files can create a mess 21
Why does my Project tab look different? 21
Instance? What is this? 24
Summary 24
Chapter 2: Introducing the Building Blocks for Unity Scripts 25
Understanding what a variable is and what it does 26
Naming a variable 26
A variable name is just a substitute for a value 30
Creating a variable and seeing how it works 32
Declaration 33
Assignment 34
Click Play! 34
Changing variables 35
Watching for a possible gotcha when using public variables 35
What is a method? 36
Using the term "method" instead of "function" 36
Table of Contents

Method names are substitutes, too 38


Introducing the class 39
Inheritance 41
The Start(), Update(), and Awake() methods, and the execution order 42
Components that communicate using dot syntax 44
What's with the dots? 44
Making decisions in code 45
Using the NOT operator to change the condition 46
Checking many conditions in an if statement 47
Using else if to make complex decisions 47
Making decisions based on user input 49
Pencil and paper are powerful tools 50
Summary 50
Chapter 3: Getting into the Details of Variables 51
Writing C# statements properly 52
Understanding component properties in Unity's Inspector 53
Variables become component properties 53
Unity changes script and variable names slightly 53
Changing a property's value in the Inspector panel 54
Displaying public variables in the Inspector panel 55
Private variables 55
Naming your variables properly 56
Beginning variable names with lowercase 57
Using multiword variable names 57
Declaring a variable and its type 58
The most common built-in variable types 59
Assigning values while declaring a variable 59
Where you declare a variable is important 61
Variable scope - determining where a variable can be used 62
Summary 63
Chapter 4: Getting into the Details of Methods 64
Using methods in a script 65
Naming methods properly 66
Beginning method names with an uppercase letter 66
Using multiword names for a method 66
Parentheses are part of the method's name 67
Defining a method the right way 67
The minimum requirements for defining a method 67

[ ii ]
Table of Contents

Understanding parentheses - why are they there? 69


Specifying a method's parameters 70
How many parameters can a method have? 71
Returning a value from a method 71
Returning the value 72
Example 73
Summary 75
Chapter 5: Lists, Arrays, and Dictionaries 76
What is an array? 76
Declaring an array 77
Storing items in the List 78
Common operations with Lists 80
List <T> versus arrays 80
Retrieving the data from the Array or List<T> 81
Checking the size 82
ArrayList 82
Dictionaries 84
Accessing values 85
How do I know what's inside my Hashtable? 86
Summary 86
Chapter 6: Loops 87
Introduction to loops 87
The foreach loop 88
The for loop 90
An example 91
The while loop 95
while versus for loops 96
Loops in statements 96
Modulo 98
Searching for data inside an array 99
Breaking the loop 100
Summary 100
Chapter 7: Object, a Container with Variables and Methods 101
Working with objects is a class act 101
A few facts 104
Example 106
Instantiating an object 107
Bored yet? 109

[ iii ]
Table of Contents

Using methods with objects 110


Custom constructors 112
Overloading 114
Summary 116
Chapter 8: Let's Make a Game! – from Idea to Development 117
Your first game – avoiding the trap of the never–ending concept 117
What do I need to learn before I start creating my own game? 118
The concept 119
Game mechanics and core components 119
Breaking the concept into smaller parts 120
Testing the mechanics 122
Level design 122
An animated 2D character 123
Physics 124
Mouse and touch controls 124
Collectables and obstacles 124
Scoring 125
UI – the user interface 126
Target platform and resolution 128
Target screen resolution 129
Summary 129
Chapter 9: Starting Your First Game 130
Setting up a new Unity project for our game 131
Backup 131
Keeping your project clean 132
Preparing the player prefab 134
Rigidbody2D 136
CircleCollider2D 137
PlayerController 138
User input 139
Jump 140
Animator 146
Running 148
Code 149
PlayerController.cs 149
Summary 150
Chapter 10: Writing GameManager 151

[ iv ]
Table of Contents

Gameplay loops 151


Singleton class 154
Starting the game 156
Setting up input keys 157
Using triggers 158
Restarting the game 161
Setting up the player starting position 161
Code in this chapter 163
Summary 166
Chapter 11: The Game Level 167
Designed levels versus generated levels 167
Creating a designed level 169
Creating a generated level 173
Planning the LevelGenerator class 174
Writing the script LevelGenerator 176
Creating a copy of the level piece 178
Instantiating 179
Vector3 179
Testing LevelGenerator 181
Extending the level 182
The code used in this chapter 184
Summary 186
Chapter 12: The User Interface 187
Introducting the Unity UI 188
Views 188
Constructing the view UI – how to keep things clean 188
Target screen resolution 189
Recognizing events 190
Buttons 192
Basic button 193
The image 193
The Button component 193
Interaction 194
The Button action 194
Hiding and showing the Canvas 196
Reference exceptions 197
GameView 200
Game over 201
The code in this chapter 202

[v]
Table of Contents

Summary 204
Chapter 13: Collectables 205
Collectables 205
The coin prefab 206
The Collectable class 210
High score and persisting data 213
Health Points and Health bar 215
Magic Points and Magic bar 217
The code in this chapter 218
Summary 225
Chapter 14: Enemies 226
What makes an enemy? 226
Movement 227
Movement by animation 227
Trigger movement 231
Making it an enemy 237
The code in this chapter 238
Summary 242
Chapter 15: Audio, 3D Games, and Export 243
How to add sound effects and music 243
Where to find sound effects and music 243
Adding music 244
Adding sound effects 248
Through animation 249
Through script 251
How to create a 3D game 252
3D models 253
3D animations 253
Animator 255
How to export and make it playable 257
Code 259
PlayerController.cs 260
Summary 262
Index 263

[ vi ]
Preface
Hello and welcome to the amazing journey of game development. This book is destined for
those who have always wanted to create a game, the ones who have thousands of good
ideas for games and people who inspire to be professional game developers. This book is
destined for you. Here, you will learn the fundamentals of how to create a game from start
to finish using Unity and C#. Step by step, you will be learning how to code and how to use
the game engine to turn your ideas into real projects. At the end of the book, you'll have
created a 2D platform game, and you will know how to create different games using the
same principles that you have learned.

What this book covers


Chapter 1, Discovering Your Hidden Scripting Skills and Getting Your Environment Ready, puts
you at ease with writing scripts for Unity.

Chapter 2, Introducing the Building Blocks for Unity Scripts, helps you develop the skill of
writing your first executable code.

Chapter 3, Getting into the Details of Variables, teaches you about creating and using C#
variables, followed editing them in Unity Inspector.

Chapter 4, Getting into the Details of Methods, helps you learn more in detail about methods
and how to use them to understand the importance of code blocks and the variables used in
them.

Chapter 5, Lists, Arrays, and Dictionaries, introduces slightly more complex ideas of
handling, lists, arrays, and dictionaries, which allow you to store many values at once.

Chapter 6, Loops, focuses on learn how to "ask" Unity to loop through a section of code and
do something useful.

Chapter 7, Objects, a Container with Variables and Methods, dives into the subjects of
organizing your code and object-oriented programming.

Chapter 8, Let's Make a Game! – from Idea to Development, explains how to turn an idea into a
ready-to-code project and how to break down complex mechanics into pieces.
Preface

Chapter 9, Starting Your First Game, outlines transforming an idea into a real Unity project.

Chapter 10, Writing GameManager, gets you acquainted with the basics of the singleton
approach and also helps you work through the gameplay loop.

Chapter 11, The Game Level, teaches how to create reusable pieces
of a level and also how to populate them to create the illusion of an endlessly running
game.

Chapter 12, The User Interface, showcases how to construct and implement the user
interface in our game.

Chapter 13, Collectables, outlines collectables and storing some data between Unity sessions.

Chapter 14, Enemies, assists in how to create enemies and obstacles, how to animate them
and how to turn simple Game Objects into deadly objects.

Chapter 15, Audio, 3D Games, and Export, assists in implementing audio effects and music,
introduces you to the fundamentals of how to create a 3D game, and finally, how we can
export the game to multiple platforms.

What you need for this book


You will definitely need a computer–PC, Mac, or any machine that supports Unity editor
installation. The complete Unity system requirements can be found at
https:/​/​unity3d.​com/​unity.

Who this book is for


The book is targeted at beginner-level Unity developers with no prior programming
experience. If you are a Unity developer and wish to create games by learning how to write
C# scripts or code, then this book is for you.

Conventions
In this book, you will find a number of text styles that distinguish between different kinds
of information. Here are some examples of these styles and an explanation of their meaning.

[2]
Preface

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "This is
the part where you have to write down instructions so that your GameObjects can be
smarter."

A block of code is set as follows:


void AddTwoNumbers ()
{
// Code goes here
}

New terms and important words are shown in bold. Words that you see on the screen, for
example, in menus or dialog boxes, appear in the text like this: "Go ahead and click Play."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book-what you liked or disliked. Reader feedback is important for us as it helps us develop
titles that you will really get the most out of.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention the


book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide at www.packtpub.com/authors.

[3]
Preface

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.

Downloading the example code


You can download the example code files for this book from your account at http:/​/​www.
packtpub.​com. If you purchased this book elsewhere, you can visit http:/​/​www.​packtpub.
com/​support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's
webpage at the Packt Publishing website. This page can be accessed by entering the book's
name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:

WinRAR / 7-Zip for Windows


Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https:/​/​github.​com/
PacktPublishing/​Learning-​C-​7-​By-​Developing-​Games-​with-​Unity-​2017-​Third-​Edition.
We also have other code bundles from our rich catalog of books and videos available
at https:/​/​github.​com/​PacktPublishing/​. Check them out!

[4]
Preface

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-
we would be grateful if you could report this to us. By doing so, you can save other readers
from frustration and help us improve subsequent versions of this book. If you find any
errata, please report them by visiting http:/​/​www.​packtpub.​com/​submit-​errata, selecting
your book, clicking on the Errata Submission Form link, and entering the details of your
errata. Once your errata are verified, your submission will be accepted and the errata will
be uploaded to our website or added to any list of existing errata under the Errata section of
that title.

To view the previously submitted errata, go to https:/​/​www.​packtpub.​com/​books/


content/​support and enter the name of the book in the search field. The required
information will appear under the Errata section.

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At
Packt, we take the protection of our copyright and licenses very seriously. If you come
across any illegal copies of our works in any form on the Internet, please provide us with
the location address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated


material.

We appreciate your help in protecting our authors and our ability to bring you valuable
content.

Questions
If you have a problem with any aspect of this book, you can contact us
at questions@packtpub.com, and we will do our best to address the problem.

[5]
Discovering Your Hidden
1
Scripting Skills and Getting
Your Environment Ready
Computer programming is viewed by the average person as requiring long periods of
training to learn skills that are totally foreign and darn near impossible to understand. The
word geek is often used to describe a person who can write computer code. The perception
is that learning to write code takes great technical skills that are just so hard to learn. This
perception is totally unwarranted. You already have the skills needed but don't realize it.
Together, we will crush this false perception that you may have of yourself by refocusing,
one step at a time, on the knowledge that you already possess to write code and develop an
awesome game from scratch.

In this chapter, we will cover the following topics:

Dealing with preconceived fears and concepts about scripts


Preparing the Unity environment for efficient coding
Introducing Unity's documentation for scripting
Explaining how Unity and the MonoDevelop editor work together
Creating our first C# script

Let's begin our journey by eliminating any anxiety about writing scripts for Unity and
become familiar with our scripting environment.
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready

Prerequisite knowledge to use this book


Great news if you are a beginner in scripting! This book is for those with absolutely no
knowledge of programming. It is devoted to teaching the basics of C# with Unity.

However, some knowledge of Unity's operation is required. We will only be covering the
parts of the Unity interface that are related to writing C# code. I am assuming that you
know your way around Unity's interface. I will help you, however, to prepare the Unity
layout for efficient scripting.

Dealing with scriptphobia


You've got Unity up and running, studied the interface, and added some GameObjects to
the scene. Now you're ready to have those GameObjects move around, listen, speak, pick
up other objects, shoot the bad guys, or do anything else that you can dream of. So you
click Play, and nothing happens. Well, darn it all anyway!

You've just learned a big lesson: all those fantastic, highly detailed GameObjects are
dumber than a hammer. They don't know anything, and they surely don't know how to do
anything.

So, you proceed to read the Unity Forums, study some scripting tutorials, and maybe even
copy and paste some scripts to get some action going when you click Play. That's great, but
then you realize that you don't understand anything in the scripts you've copied. Sure, you
probably recognize the words, but you fail to understand what those words do or mean in a
script.

You look at the code, your palms get sweaty, and you think to yourself, "I'll never be able to
write scripts!" Perhaps you have scriptphobia: a fear of not being able to write instructions (I
made that up). Is that what you have?

The fear that you cannot write down instructions in a coherent manner? You may believe
you have this affliction, but you don't. You only think you do.

The basics of writing code are quite simple. In fact, you do things every day that are just like
the steps executed in a script. For example, do you know how to interact with other people?
How to operate a computer? Do you fret so much about making a bologna sandwich that
you have to go to an online forum and ask how to do it?

[7]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready
Of course you don't. In fact, you know these things as everyday routines or maybe habits.
Think about this for a moment: do you have to consciously think about the routines that
you do every day? Probably not. After you do them over and over, they become automatic.

The point is that you do things every day following sequences of steps. Who created these
steps that you follow? More than likely, you did, which means that you've been scripting
your whole life.

You just never had to write down the steps for your daily routines on a piece of paper
before you did them. You could write the steps down if you really wanted to, but it takes
too much time and there's no need for it; however, you do in fact know how to. Well, guess
what? To write scripts, you only have to make one small change, start writing down the
steps, not for yourself but for the world that you're creating in Unity.

So as you can see, you are already familiar with the concept of dealing with scripts. Most
beginners of Unity easily learn their way around the Unity interface, how to add assets, and
working in the Scene and Hierarchy windows. Their primary fear and roadblock is their
false belief that scripting is too hard to learn.

Relax! You now have this book. I am going to get really basic in the early chapters. Call
them baby steps if you want, but you will see that scripting for Unity is similar to doing
things that you are already doing every day. I'm sure you will have many Aha moments as
you learn and overcome your unjustified fears and beliefs.

Downloading Unity
You have probably already installed and activated Unity. Where you should look for the
latest Unity version and license might be obvious. However, I've noticed lots of questions
online about where you can get Unity for free, and so I decided to cover this subject. If you
feel that this step is unnecessary for you, skip this part.

The best place to download your Unity copy from is, of course, Unity's official
website: https:/​/​store.​unity.​com/​download?​ref=​personal.

In this book, we will be covering Unity Version 2017.1.1 and higher. We need to download
the latest version of Unity and install it with all components ticked. It's a good idea to install
Unity with the example project. The Unity Example project (the Angry Bots game) is there
for us to play with, experiment, and learn.

[8]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready
Unity has a store where we can also download more example projects and start playing
around with them. To access the store, you can do it online or directly from the Unity
engine, so don't worry if you forgot to check the Unity Example project in the installation
menu because you can download it at any time.

Obtaining a free license


The easiest way to obtain a Unity license is by simply launching Unity for the first time. The
following steps will guide you through it:

1. Fill in your details so that Unity Technologies can send you your Unity free
license code.
2. Unity will present the License management window. Chose the Unity Personal
(free version).
3. You should receive a verification email with a Confirm email button. Once you
have clicked it, you should be able to log in to Unity.

You are now all set with the latest version of Unity and a free license!

Teaching behavior to GameObjects


You have Unity because you want to make a game or something interactive, such as an AR
or VR experience. You've filled your game with dumb GameObjects. What you have to do
now is be their teacher. You have to teach them everything that they need to know to live in
this world of make–believe. This is the part where you have to write down instructions so
that your GameObjects can be smarter.

Here's a quote from the Unity Manual:

"The behavior of GameObjects is controlled by the Components that are attached to them...
Unity allows you to create your own Components using scripts."

Notice the word behavior. It reminds me of a parent teaching a child proper behavior. This is
exactly what we are going to do when we write scripts for our GameObjects: we'll teach
them the behaviors we want them to have. The best part is that Unity has provided a long
list of all the behaviors that we can give to our GameObjects. This list of behaviors is
documented in the Scripting Reference.

[9]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready
This means that we can pick and choose anything that we want a GameObject to do from
this list of behaviors. Unity has done all the hard work of programming all of these
behaviors for you. All we need to do is use some code to tie into these behaviors. Did you
catch that? Unity has already created the behaviors; all that we have to do is supply a bit of
C# code to apply these behaviors to our GameObjects. Now, how difficult can it really be
since Unity has already done most of the programming?

Using Unity's documentation


When we begin writing scripts, we will be looking at Unity's documentation quite often, so
it's beneficial to know how to access the information we need. For an overview of a topic,
we'll use the Reference Manual, and for specific coding details and examples, we'll use the
Scripting Reference.

There are a number of ways to access the Unity documentation:

Through the Unity website at


http://docs.unity3d.com/ScriptReference/index.html.
Through the Help menu on the top bar. In this way, you can access a local copy
of Unity reference as we can see in the following image. This is worth
remembering if there are internet connectivity issues:

[ 10 ]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready
Let's open Scripting Reference now and search for a GameObject:

Through the Help menu next to the component name. This will work only for
Unity's built-in, standard components.

This is the place where we can find scripting documentation, answers to our questions, and
a lot of example code. You might feel a bit lost right now, but don't worry, this is quite
normal. The Unity documentation is really easy to use. For the fastest access to relevant
information, use Search scripting... in the top–right corner, as shown here:

[ 11 ]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready

The whole reason Scripting Reference exists is so that we can look for
information as we need it. This will actually make us remember the code
that we write over and over, just like our other daily routines and habits. It
is a very good idea to take a brief look through the most common Unity
objects, such as GameObject, Transform, MonoBehaviour, and Renderer.

C# documentation – where to find it and


do I need it at all?
Another resource that we will be using is Microsoft's C# scripting documentation. We can
access it at https://msdn.microsoft.com/en-us/library/67ef8sbd.aspx.

Let's not worry about it too much at the moment. We agreed to take baby steps, so
bookmark this link in your web browser for now.

[ 12 ]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready

The Unity community – asking others for help


You are planning to become a game developer, or are using Unity for other interactive
projects. During production, at some point, you will definitely need help from other
developers. Unity has a very dedicated community of developers who are always keen to
help each other.

When we encounter some hurdles, why not ask others? In most cases, there is someone like
you out there with similar issues that have been resolved. A good place to talk about issues
in your project is in the Unity Forums. Go ahead and create a forum account now! Don't be
shy; say "hello" to others! Unity Forums are also the perfect place to read announcements
about upcoming updates.

Use Unity Forums to read about others' work, share your work, and connect with other
developers at http://forum.unity3d.com/.

Use Unity Answers to ask specific questions about issues that you have encountered.
Remember to be very specific, try to describe the problem in detail, and don't ask general
questions. For example, don't ask, "Why is my GameObject not moving?" Instead, ask
specifically, "GameObject not moving when adding a rigid body force" and then describe
the details. Posting your code under the question is also a very good idea.

Working with C# script files


Until you learn some basic concepts of programming, it's too early to study how scripts
work, but you still need to know how to create one.

There are several ways of creating a script file using Unity:

1. In the menu, navigate to Assets | Create | C# Script


2. In the Project tab, navigate to Create | C# Script
3. Right-click on the Project tab, and from the pop–up menu, navigate to
Create | C# Script

All of these ways create a .cs file in the Unity Assets folder. From now on, whenever I tell
you to create a C# script, use whichever method you prefer.

[ 13 ]
Discovering Your Hidden Scripting Skills and Getting Your Environment
Chapter 1
Ready

Creating a C# script file


We are now ready to create a new C# file in our learning project:

1. Create a new Unity project and name it Learning Project


2. Right-click on the Project tab and create a folder named Scripts
3. Right-click on the Scripts folder, as shown in the following screenshot, and
create a C# script:

4. Immediately rename NewBehaviourScript to LearningScript

We have created the Scripts folder, which we will be using to organize our C# files. This
folder will contain all of our Unity script files. We have also used Unity to create a C# script
file named LearningScript.cs.

Introducing the MonoDevelop code editor


Unity uses an external editor to edit its C# scripts. Even though it can create a basic starter
C# script for us, we still have to edit the script using the MonoDevelop code editor that's
included with Unity.

Syncing C# files between MonoDevelop


and Unity
Since Unity and MonoDevelop are separate applications, Unity will keep MonoDevelop
synchronized with itself. This means that if you add, delete, or change a script file in one
application, the other application will reflect the changes automatically.

[ 14 ]
Another random document with
no related content on Scribd:
Aunt Sophia Primshock’s eyes, if it could not sneak in through her
ears. On the very next morning after Pee-wee’s brief career upon the
stage he received the following letter:

My dearest nephew Walter:


We were so pleased to see in the Council Fire column of a
newspaper that you have been awarded the scout badge for first
aid to animals. Prudence is so proud of her cousin that she
cannot wait to see you and tell you so. When we think of all the
cruelty that is inflicted on poor dumb creatures, and sometimes
by boys, it makes me very happy to think that my very own
nephew stands as the champion of the beasts and birds, and
will not harm them or allow anyone else to harm them. That is
better than selling sausages like a pedler, and if it is true that
they are made of dogs it makes one’s heart ache to think of it.
We want you to come here and see us very soon, and you must
stay for several days.
Your proud and happy
AUNT SOPHIA

Enclosed in the envelope was another missive, rather more formal


in tone, which read:

TO WALTER HARRIS, SCOUT:⸺


The Humane Committee of the Girl Scouts of North Deadham
invite you to attend their rally on Saturday evening, July the
tenth, and to accept the Black Beauty Cross of Mercy, for
friendship and kindness to dumb creatures. This cross is given
only by the North Deadham organization, to those rendering
conspicuous service in the field of humanity by championing our
dumb friends who cannot speak for themselves.
Katherine Kindheart
Sympathea Softe
Dorothy Docile
Prudence Primshock
Committee
The hero’s acceptance of this invitation was a little disconcerting,
but it did not dim his glory. On the contrary (so far as his own efforts
were concerned) it increased his glory. He wrote:

Dear Aunt Sophia and Prudence and that Committee too:


I got that animal first aid badge so now I have ten badges
only I didn’t get it yet but anyway, I’m a star scout. You have to
have a general knowledge of farm animals and I know a lot
about them and I was kicked by a cow and she spilled the milk. I
like milk too. I know what’s good for colic and you have to know
that and it’s good for a horse. I don’t mean colic.
Once when I was drowning some kittens I saved two so that
was a kind act to those two and that counts. It counts one point.
I fixed a tin can that was tied to a dog’s tail because it was tied
too tight. I know all about the different knots, too. Once I
grabbed a bat because I thought it was a dish rag hanging up. I
bet most girls wouldn’t be kind to mice especially rats.
If a horse falls down you have to take off his harness and the
thing that goes kind of alongside his neck comes off like
suspenders. Anyway I like a belt better on account of wearing
my belt axe. Gee whiz I like girls and every kind of animals, only
they’re scared when they get in a rowboat.
I read that story about Black Beauty that your badge is
named after. I like elephants better. If you have a parrot you
better not swear because he learns it. Scouts have to cut birds
up in sections so as to tell the different parts of them. I’m going
to wear that Black Beauty badge alongside my star badge. I’m
going to go on the train that gets there in time for supper.
With love,
WALTER HARRIS
First Aid
Physical Development
Personal Health
Public Health
Life Saving
Astronomy
Swimming
Forestry
Dairying
Animal First Aid that makes ten.
P. S. I don’t mean you have to cut birds up alive only in pictures.

Aunt Sophia put on her spectacles and scrutinized this letter


curiously, but in the end her eyes dwelt fondly on the words at the
end of the list of badges. Pee-wee always thus summarized his
glories, even in school examination papers. She gazed at the words
Animal First Aid and was reassured.
As for Sympathea Softe and Katherine Kindheart and Dorothy
Docile, they were greatly edified by the imposing list of Pee-wee’s
triumphs.
“Physical Development,” said Dorothy, in whispered admiration; “I
just bet he’s tall and dark, with a splendid chest. One can be big and
gentle at the same time.”
“Of course,” said Sympathea, “look at elephants; they’re as gentle
as can be.”
“Oh, I hope he isn’t like an elephant,” said Dorothy; “they’re so
clumsy. And they just eat, eat, all day. They just live on peanuts.”
“I pictured him as tall and lithe,” said Miss Katherine Kindheart;
“like a—like a tree. I think that one familiar with forestry is almost
sure to be tall. The swimming award too! Oh, I just long to see him. I
think that forestry is such perfectly scrumptious word too. Forestry! It
sort of reminds me of Daniel Boone and Buffalo Bill—calm and
stately; you know what I mean.”
“Or General Pershing,” said Sympathea.
“Or Eugene O’Brien,” said Dorothy, who was something of a
movie fan.
“Oh don’t you just long to see him?” they all asked each other.

1 Pioneer scout; a lone scout; one without troop or patrol affiliations.


CHAPTER IV—HE ADVANCES
Pee-wee started for North Deadham in full scout regalia, carrying
a duffel bag instead of a suitcase, wishing to detach himself as much
as possible from the manners and customs of civilization. A new
feature of his motley array was a can-opener dangling from his belt,
intended to suggest the rugged scout’s dependence on his own
culinary art in the dense wilderness. It was rather suggestive of
Heinz 57 varieties.
On the train he made some memorandums in his scout report
book looking to the future government of his new patrol. The
following is a sample.
If any hop-toad can’t learn the pace he has to have his legs tied
together for an hour.
Every feller that gets a new hop-toad gets a piece of chocolate but
he has to give it to his patrol leader for the treasury.
If a hop-toad can’t croak like a frog he has to be turned over on
his back and somebody sit on him till he croaks.
A hop-toad has to be given to the tom-cats if he can’t learn
because the tom-cats want more because they only have six.
On account of going fast hop-toads have to have sticks in their
mouths.
I’m going to try to get tents near where the Robins were before the
other fellows chased them away.
When the train stopped at North Deadham, the girls of the
Humane Committee saw descending from it a diminutive figure clad
in khaki, and Solomon in all his glory was not arrayed like him. His
scout report book bulged out of his pocket, his jack-knife and his
compass and his can-opener jangled in a kind of martial tune, his
step was the step of a conqueror. Beneath his flapping scout hat his
curly hair showed and upon his face was a frown, a terrible frown,
the frown of a hero.
The only discordant note in the martial figure that he presented
was the stick of lemon candy which he was sucking. During his ride
various articles, chiefly edible, had been left upon his lap for
inspection, and he bought them all, and they now bulged and
protruded here and there upon his scout attire.
Removing the stick of lemon candy from his mouth, he
contemplated the girls who had come to meet him, uttered the single
word “Hello” and replaced the candy in his mouth.
“Did you ever in your life?” gasped Sympathea.
“He is certainly not an elephant,” said Dorothy.
“Or a Daniel Boone or a Buffalo Bill,” chimed in Miss Kindheart.
“I’d rather be myself than them,” said Pee-wee.
“Yes, why?” asked one of the reception committee anxiously.
“Because they’re dead.”
“Oh, we’re so glad to see you, Walter,” said Cousin Prudence,
embracing him till he rattled like a Ford car; “I thought you’d never,
never, come to see us. And you’ve won the animal first aid badge!
Oh, isn’t that perfectly wonderful!”
“I won a lot of others too,” Pee-wee said; “I’ve got nine badges.
See them on my sleeve? When the tenth one is put there I’ll be a
star scout. I’m going to be a patrol leader, too. I lost a marshmallow
on that train. Are you going to have that meeting to-night?”
“We certainly are and you’re going to be the main attraction.
You’re going to sit on the stage! Isn’t that just perfectly fine? I don’t
believe you’ve ever been on a stage, now have you? Do you think
you’ll be afraid?”
It was very hard for Pee-wee to admit that there was anything in
the world he hadn’t done; and to have it intimated that he, the actor
in Double-crossed, had never been on the stage, was as much as he
could bear. But he remembered his voluntary promise to his mother
and modified his answer.
“Sure, I’ve been on platforms and they’re the same as stages,” he
said; “only they’re kind of different. When we get our awards we
have to go on platforms. Do you think I’m scared of audiences? Gee
whiz, they won’t hurt you. I’m not even scared of bears and they’re
not as bad as audiences, that’s one thing sure.”
“But I mean a regular stage,” chirped Sympathea, “with woods
painted in back and everything.”
“I’ve even been lost in the woods,” Pee-wee announced proudly.
“Do you think I’m scared of painted woods? You can’t get lost in
those. I’ve been—I’ve been—famished in the woods, when I was
lost.”
“I thought scouts never got lost,” Miss Dorothy Docile carolled
forth.
“That shows you don’t know anything about them,” Pee-wee said
disdainfully; “they know all about getting lost; they get lost better than
anybody else. Then they find their way out by resourcefulness. Do
you know what that means?”
“Isn’t that perfectly wonderful?” said Miss Katherine Kindheart.
“That’s nothing,” Pee-wee said; “you go around in a circle when
you get lost; do you know why?”
“No, do tell us.”
“Because your heart is on your left side. You have to know all
about astronomy if you’re a scout.”
“That isn’t astronomy, that’s anatomy,” said Cousin Prudence.
“Woods is my middle name,” said Pee-wee.
“Isn’t that a perfectly lovely name?” said Sympathea. “Walter
Woods Harris.”
“I don’t mean it’s really my middle name,” Pee-wee said. “Suppose
I was crazy about mince pie. I’d say my middle name was mince pie,
but it wouldn’t be Pee-wee, I mean Walter Mincepie Harris, would it?”
“And do you really go round in a circle when you get lost?” Cousin
Prudence asked him.
“S-u-re,” said Pee-wee conclusively, “your left side goes ahead of
your right side—”
“And what becomes of your right side?” Katherine asked.
“It comes along after your left side,” Pee-wee explained.
“And doesn’t it ever, ever catch it?”
“No, so that’s why you go round in a circle; see? Now I’ll close my
eyes and try to go straight. I’ll show you.”
The demonstration of this item of scout lore was highly
satisfactory and very scoutish; for scouts are supposed to smile and
Pee-wee’s escort of honor did more than that, they screamed.
Closing his eyes, Pee-wee strode forward verging more and more
toward the curb until he stumbled and went head over heels into the
gutter, where his feminine admirers gathered about him, clamoring to
aid the hero.
Pee-wee was equal to the occasion. “A scout is supposed to
spread mirth,” he said, rising and brushing the mud from his regalia.
He had certainly spread mirth as thoroughly as the mud was spread
upon his scout uniform. “I’ll tell you something else about anatomy
too,” he said. “Just then when I fell down in the mud it reminded me
of it. Do you know how many muscles it takes to make a smile?”
“No, do tell us,” said Cousin Prudence as she brushed him off,
laughing uncontrollably.
“Thirteen,” said Pee-wee.
“No wonder you were unlucky,” said Sympathea, shaking with
laughter.
“It takes sixty-four muscles to make a frown,” Pee-wee continued.
“So you’re doing a lot of extra work if you frown,” he added, pulling
up his torn stocking.
The girls’ Humane Committee must have been of an economical
turn, for they did not use sixty-four muscles, or anything like that
number. They roared and screamed, and held their sides and
brushed him off and readjusted his official junk upon his diminutive
person, and just kept on laughing and laughing and laughing.
CHAPTER V—HE STORMS THE INNER
FORTRESS
Having risen from the gutter like so many world heroes who began
as poor boys, Pee-wee proceeded to expatiate on the honorable
company which had come out of that lowly and muddy abode into
the dazzling halls of fame.
“That’s where Mr. Temple began who started Temple Camp,” he
said. “Wait till I see if I’ve got my money all right; I’ve got seven
dollars and fifty-two cents not counting my ticket because my father
paid for that. I’ll treat you all to sodas.”
“Oh I just couldn’t eat a thing while I’m laughing so,” Miss Dorothy
Docile explained; “thank you just as much.”
“Can’t you eat when you’re laughing?” Pee-wee asked
incredulously.
“No, can scouts eat while they laugh?”
“S-u-re, they can eat while they’re sleeping even. If you dream
about eats they taste just as good don’t they?”
“Can they eat while they’re going around in a circle?” Sympathea
asked mischievously. “You know we’re girl scouts, but we really don’t
know much about girl scouting, because we’ve only just started.
Don’t you think our Black Beauty award is a splendid idea?”
“Sure, I have lots of dandy ideas,” Pee-wee said; “but anyway
you’ve got a right to kill snakes—snakes and mosquitoes. But I
haven’t got any right to kill a lion.”
“Oh, I hope you never did that,” said Cousin Prudence.
“Sure I didn’t,” Pee-wee assured her.
If any proof of his courage was required, he gave it in his martial
advance up the wide, old-fashioned, thickly carpeted stairway which
led to the inner fortress where Aunt Sophia Primshock sat bundled
up in a big wheel chair. No weapon had she but her spectacles, but
she used those in such a way as to make her terrible to behold. Her
eyes made sudden flank movements around the side of them; they
went “over the top” as well; and peered straight through them in a
way of terrible scrutiny.
Aunt Sophia Primshock had all kinds of money and several
different kinds of rheumatism. As fast as there was a new kind, she
secured it. She was very deaf, but not too deaf to hear Pee-wee. It
was not quite as bad as that. Next to her collection of rheumatics
was her collection of cats. In the august presence Pee-wee now
appeared in all his scout glory—marred only by a hole in his stocking
—followed by Cousin Prudence.
“I am very glad to see my nephew,” said Aunt Sophia, as Pee-wee
advanced to receive her kiss, “and I am not only glad but proud to
call him my nephew,” she added. “I don’t know much about this
scouting, I’m afraid it makes boys a little wild. But when a boy
registers his friendship for dumb creatures I am proud, more than
proud, to call him my nephew. You have seen the girl’s committee?
They are dear, sweet girls, all of them.”
“Oh yes, he fell for us, Mother,” said Prudence.
“Fell for you?”
“Yes, he fell all over himself, but he isn’t hurt.”
“And what is better still, he would not inflict any hurt,” said Aunt
Sophia. “And what a fine boy he is, eh Prudence? A splendid, kind,
humane boy, with a heart—”
“On his left side, Mother,” said Prudence; “he proved it to us and
we know he has a heart.”
Aunt Sophia smiled indulgently. Like most persons who are under
the spell of one idea she was not even curious about matters in
general. It was perfectly evident that she had captured the helpless,
struggling, little Girl Scout troop and turned it into a humane society.
There was no doubt that the “committee” had originated in that
solemn apartment.
“You can kill snakes because they kill birds,” Pee-wee said; “and
cats kill birds too.”
There was no answer to this so Aunt Sophia said, “I was so happy
when I heard—saw it printed in a newspaper—that my nephew had
won the badge for first aid to dumb creatures.” (Aunt Sophia always
called animals dumb creatures.) “That is better than running after
circuses and going to—to shows. Isn’t it? I had a brother, a very dear
and promising brother, many, many years ago, and he joined a
troupe of play actors, which made his poor mother very, very sad.”
Pee-wee wriggled nervously but listened with respect. “The scout
boys, they don’t—they don’t fill their brains with—with wild west
shows? What is that you have there?”
“That’s my handbook, and this is my scout report book,” Pee-wee
exclaimed, glad enough to expound the ins and outs of scouting.
“Ah yes, and if you do a kind act you jot it down?”
“Sure.”
“Let me see them,” said Aunt Sophia holding out her hand; “my
arm is very stiff. Did you bring me my tea, Prudence dear?—I eat
very little and go about almost none at all. I am very, very stiff.”
“That’s because you don’t sleep outdoors,” Pee-wee said. “I bet if
you went scout pace you wouldn’t be stiff. Do you want me to show
you how?”
“Goodness gracious no, my dear! Let me see what is in the books
—”
“Rolling down hills is good too,” said Pee-wee; “I bet if you try that
you won’t be stiff. Lots of scouts roll down in barrels, because that
shakes them up. I’ll get a barrel for you if you want to try it.”
Aunt Sophia did not want to try it, but she was presently to be
shaken up in quite another way. Gazing with increasing severity
through her spectacles she saw sprawled upon the page the
dreadful words.

If any hop-toad can’t learn the pace he has to have his legs
tied together for an hour.
Every feller that gets a new hop-toad gets a piece of
chocolate—
If a hop-toad can’t croak like a frog he has to be turned over
on his back and somebody sit on him till he croaks.
Aunt Sophia looked up, dumbfounded, speechless. She
readjusted her spectacles, as if even they might be deceiving her,
and read:

A hop-toad has to be given to the tom-cats—

She read no more. Rather she saw the page in a kind of trance.
Her astonished eyes jumped from one blood-curdling memorandum
to another, picking out the more heartless words and phrases. Given
to the tom-cats ... chased the Robins away ... turned on his back till
he croaks ... hop-toads ... sticks in their mouths....
Horrors, oh horrors! Here before her very eyes was a series of
recipes for cruelty! Directions, suggestions, memorandums written in
cold blood for the torture of hop-toads!
Pee-wee sensed the situation, but it was too late. The hop-toads
were already on their backs, the sticks were in their mouths, they
were croaking, or being fed alive to tom-cats, the robins had been
chased from their nests and their little ones, the boys were standing
around eating chocolate while the toads suffered, the massacre was
on.
“I’ll tell you all about it,” Pee-wee said, facing the awful face of his
outraged aunt. “You see hop-toads, they’re really not hop-toads; do
you see?”
“I do not see,” said Aunt Sophia.
“I’ll tell you all about it. Scout patrols are named after animals;
there’s a patrol at Temple Camp named the Robins, see? My new
patrol is going to be named the Hop-toads, because they’re all going
to be good at scout pace, see? Gee whiz, you don’t care if we make
fellers hold sticks in their mouths, do you? Because they can run
better that way. A hop-toad means a—a scout. I’m a hop-toad.
Maybe I don’t look like one but I am.”
Aunt Sophia was just about convinced—by a very, very narrow
margin. She was convinced, but she remembered the awful things
upon that fly-leaf. She was still a little, just a very little, suspicious.
But she accepted Pee-wee’s explanation....
CHAPTER VI—CARRIED BY A MINORITY
That same memorable Saturday was the day on which Pee-wee’s
troop was to go to its summer quarters at the beloved Temple Camp.
As every scout knows, Temple Camp is a little in from the Hudson
River in the neighborhood of Catskill.
North Deadham is about thirty-five miles north of Bridgeboro.
Roughly speaking, North Deadham would be on a line between
Bridgeboro and Temple Camp. The brilliant idea of spilling the beans
in North Deadham is attributable to Artie Van Arlen, patrol leader of
the Ravens—Pee-wee’s own patrol.
“What do you say if two or three of us start hiking on Friday and
camp along the way and bang into North Deadham in time to foil our
young hero?” said Artie. “Foiling is his middle name, so we’ll try a
little of it. Then we’ll wrap him up and take him along to camp with
us. What do you say?”
“You mean hike all the way?” asked Connie Bennett of the Elks.
“Sure.”
“Declined with thanks,” said Connie. “Let him stay there a while.
What’s the use of starting out hunting for trouble? He’s wished onto
the Ptomaine Committee or whatever they call it; let them worry for a
while.”
“Anybody in the Silver Foxes want to hike it?” Artie asked.
“We promised Mr. West of the West Shore Railroad, we’d go that
way,” said Roy; “we can’t break our words. The train will be waiting
for us.”
“Some scouts!” said Grove Bronson of the Ravens.
“I’d just love to stop at North Deadhead for our young hero,” said
Hunt Ward of the Elks, “but you know how the directors of the
railroad would feel.”
“Sure, a scout’s honor is to be trusted,” said Roy.
“How about his feet?” Artie shot back. “Can you walk from the
station to the train? You make me tired, you fellows.”
“If you’re so tired what do you want to hike for?” Roy asked.
“You’re so wide awake and full of pep, what do you want to go to
Fried ham or Dead-ham for? I should worry about Deadville or
whatever you call it. Right away when we get rid of Pee-wee you
want to go and get him. They’ve just had whooping cough at Temple
Camp; isn’t that bad enough? The raving Ravens are raving again,
no wonder the railroads are losing money with the Raven Patrol
walking all over the country.”
“Who’ll volunteer?” Artie said.
“A large chunk of silence,” said Roy.
“I won’t,” called one.
“Neither will I,” shouted another.
“Not for mine,” piped up a third.
“We’ll all volunteer not to hike,” said Roy. “Let the scouts in the
books do the hiking.”
“I will,” said Grove Bronson.
“He hasn’t got the railroad fare,” shouted Roy.
“All right,” said Artie, “you and I’ll hike together, Grove; we’ll take
the north turnpike—”
“Be sure to put it back when you get through with it,” said Roy,
“and give our kindest regards to the animated animal cracker and if
you’re going to hike from Deadtown to camp the best way is to follow
the Franklin Turnpike as far as Idaho and take the second turn to
your left. That’ll take you into the Great Salt Lake. Don’t hurry, take
your time.”
“The pleasure is ours,” said Artie.
“If you don’t get to camp till next summer it’ll be all right,” said Roy.
“Tell Pee-wee he’ll find us near the lake and we hope he’ll drop in.”
CHAPTER VII—MENTAL TELEGRAPHY
Thus it happened that while Scout Harris, friend and champion of
the dumb creatures, was preparing to receive the tribute that was
due him, two scouts of his patrol were tramping along the dusty road
as the sun went down, on the last part of their long hike to North
Deadham. They crossed the frontier of the village unnoticed. The
only sentinel there was a rooster on a fence and he was asleep at
his post, or rather his perch.
The invading column passed through McCrockett’s Lane and
rested under a weeping willow tree, where they kindled a little fire
and brewed some coffee and fried some bacon. If the weeping
willow could but have known their business it would have laughed
rather than wept.
Their supper finished, the invaders trampled the fire out and
played mumbly peg under the tree just as if nothing were going to
happen. Scout Harris said afterward that just at that time (seven
thirty) a strange desire for fried bacon came over him and that he
smelled coffee. Thus soul speaks to soul across space in the mystic
realm of scouting!
At exactly eight o’clock by a cow-bell in a neighboring field,
verified by their own trusty scout watches, the invaders followed a
northwesterly course through the village square into Gordon’s Hollow
and thence to Main Street and to a certain commissary where they
made ready for the terrible work in hand by two stimulating ice cream
cones, which sent the blood coursing through their veins and gave
them strength and courage.
Passing the district school with great caution they succeeded in a
skilfully conceived flank move around the entire police department,
who was standing on a corner talking with an unsuspecting citizen.
This was at exactly seven minutes after eight by the town hall clock
which wasn’t going, no doubt in honor of the great occasion.
Singular to relate, at precisely four minutes after eight by Pee-
wee’s reliable scout watch, and just as he was starting with his
cousin Prudence for the church lecture hall, he was conscious of a
shivering and decided to return and get his scout jacket. It was at
that very moment that the invading legion partook of ice cream
cones. Perhaps it was only a coincidence but so strong was the
thought of ice cream cones in Pee-wee’s mind that he bought two
(treating his cousin Prudence) on their way to the church. A most
singular and harrowing thing to relate is that these two separate
parties almost met in Pop Carroway’s Candy Parlor.
The lecture room of the church was ablaze with light from eight
kerosene lamps. One of these had a reflector on it, to be used
perhaps as a sort of spotlight on the hero’s entrance.
Aunt Sophia, by reason of her collection of aches and pains, did
not attend this gala meeting. She stayed at home with her cats. But
the minister was there and the Girl Scouts from South Deadham and
Deadham Centre were there.
This gay outpouring of nearly fifty people was not exactly in honor
of Pee-wee. It was a Girl Scout rally intended to stir up interest in the
local movement. But since Pee-wee, like a true scout, was always
prepared to take whatever came along, he appropriated all the stray
glory that was floating around.
Being the only boy in town, he was something of a lion and was
viewed with becoming awe by the spectators as he sat wedged in
between his cousin Prudence and one of the other girls on the
platform. His martial appearance was somewhat modified when he
pulled up his rebellious stocking, but his frown was terrible and his
belt axe was so skilfully displayed as to strike dismay to the most
courageous heart.
His nine merit badges (the final badge still lacking) were revealed
upon his sleeve. He and the two maidens who flanked his sturdy
form occupied but two chairs and from the rear of the little meeting
room Artie Van Arlen and Grove Bronson, lurking there unseen,
beheld the picture of these three as a sort of human sandwich (the
kind sold at railroad stations) with the middle part of almost
microscopic proportions. All of the valor in Scout Harris’s diminutive
body seemed to be squeezed up into his head by the flanking
pressure of his feminine hostesses and he gazed out upon the
assemblage, silent, uncomfortable, terrible.
The organization business of the evening being concluded and a
couple of songs about the woods having been sung, Miss
Sympathea Softe arose, replaced a straying lock of hair with skilful
daintiness, wriggled a little with becoming stage fright, and
proceeded to explain the happy idea which the Girl Scouts had hit on
in the Black Beauty Award.
CHAPTER VIII—A PREDICAMENT
“Humanity and kindness,” she said in finishing, “are as broad as
the skies. So we planned not to confine our award to our local circle
or even to Girl Scouts everywhere. There are Boy Scouts as well
and we must not forget them.”
“There are more of them than there are Girl Scouts,” Pee-wee
spoke up, “because I can prove it—”
“And their activities are reported in newspapers throughout our
country—”
“They’re in Boys’ Life too,” Pee-wee announced vociferously, to
the great amusement of the audience.
“The Boy Scouts,” continued Sympathea, “have an award called
the First Aid to Animals Badge. It is the intention of our little troop to
tender the Black Beauty Cross to every scout winning that award.
The first one that we are going to honor is the cousin of one of our
members, Prudence Primshock; a scout from Bridgeboro, New
Jersey, a star scout who has won the badge that stands for
humaneness in his troop—Walter Mincepie Harris—”
“Good night, he’s disguised as a mince pie,” Grove whispered to
Artie; “the plot grows thicker, as Roy would say.”
“Excuse me,” said Sympathea blushing, “I mean Walter Woods
Harris. I’m just a little nervous and (great and reassuring applause) I
hardly know what I’m saying. We all know that Boy Scouts are
heroes, that their hearts are always on the left, I mean on the right, I
mean they’re in the right place. Walter—Scout Harris, will you please
stand up and—”
“Hold while there is yet time!” came a voice from the rear of the
little lecture room. “Water Mincepie Harris is not what he seems! He
has disgraced the beloved mince pie and he is trying to deceive you
all!”
“It’s Grove Bronson!” shouted Pee-wee, jumping from his seat.

You might also like