PDF 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 Ebook Full Chapter

Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

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
Visit to download the full and correct content document:
https://textbookfull.com/product/learning-c-by-developing-games-with-unity-2020-an-e
njoyable-and-intuitive-approach-to-getting-started-with-c-programming-and-unity-fifth-
edition-harrison-ferrone/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Learning C 7 By Developing Games with Unity 2017 Learn


C Programming by building fun and interactive games
with Unity Third Edition Micael Dagraca

https://textbookfull.com/product/learning-c-7-by-developing-
games-with-unity-2017-learn-c-programming-by-building-fun-and-
interactive-games-with-unity-third-edition-micael-dagraca/

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/

Learning C# programming with Unity 3D Alex Okita

https://textbookfull.com/product/learning-c-programming-with-
unity-3d-alex-okita/
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/

Programming With STM32: Getting Started With the Nucleo


Board and C/C++ Donald Norris

https://textbookfull.com/product/programming-with-stm32-getting-
started-with-the-nucleo-board-and-c-c-donald-norris/

Getting Started with Unity 2018 A Beginner s Guide to


2D and 3D Game Development with Unity 3rd Edition
Edward Lavieri

https://textbookfull.com/product/getting-started-with-
unity-2018-a-beginner-s-guide-to-2d-and-3d-game-development-with-
unity-3rd-edition-edward-lavieri/

Mastering UI Development With Unity An In Depth Guide


to Developing Engaging User Interfaces with Unity 5
Unity 2017 and Unity 2018 1st Edition Ashley Godbold

https://textbookfull.com/product/mastering-ui-development-with-
unity-an-in-depth-guide-to-developing-engaging-user-interfaces-
with-unity-5-unity-2017-and-unity-2018-1st-edition-ashley-
Learning C# by Developing
Games with Unity 2020
Fifth Edition

An enjoyable and intuitive approach to getting started with C#


programming and Unity

Harrison Ferrone

BIRMINGHAM - MUMBAI
Learning C# by Developing Games with
Unity 2020
Fifth Edition
Copyright © 2020 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 or its dealers and distributors, will be held liable for any damages caused or alleged to
have been 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.

Commissioning Editor: Pavan Ramchandani


Acquisition Editor: Ashitosh Gupta
Content Development Editor: Akhil Nair
Senior Editor: Hayden Edwards
Technical Editor: Deepesh Patel
Copy Editor: Safis Editing
Project Coordinator: Kinjal Bari
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Production Designer: Nilesh Mohite

First published: September 2013


Second edition: March 2016
Third edition: December 2017
Fourth edition: March 2019
Fifth edition: August 2020

Production reference: 1200820

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.

ISBN 978-1-80020-780-6

www.packt.com
"If people reach perfection they vanish, you know."

The Once and Future King


Packt.com

Subscribe to our online digital library for full access to over 7,000 books and videos, as well
as industry leading tools to help you plan your personal development and advance your
career. For more information, please visit our website.

Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Fully searchable for easy access to vital information

Copy and paste, print, and bookmark content

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.packt.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.

At www.packt.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.
Contributors

About the author


Harrison Ferrone was born in Chicago, IL, and was raised all over. Most days you can find
him writing technical documentation at Microsoft, creating instructional content for
LinkedIn Learning and Pluralsight, or tech editing for the Ray Wenderlich website.

He holds various fancy looking pieces of paper from the University of Colorado at Boulder
and Columbia College, Chicago. Despite being a proud alumnus, most of these are stored
in a basement somewhere.

After a few years as an iOS developer at small start-ups, and one Fortune 500 company, he
fell into a teaching career and never looked back. Throughout all this, he's bought many
books, acquired a few cats, worked abroad, and continually wondered why Neuromancer
isn't on more course syllabi.

Completing this book wouldn't have been possible without the support of Kelsey, my
partner in crime on this journey, and Wilbur, Merlin, Walter, and Evey for their
courageous spirits and gracious hearts.
About the reviewers
Andrew Edmonds is an experienced programmer, game developer, and educator. He has a
Bachelor of Science degree in Computer Science from Washburn University and is a Unity
Certified Programmer and Instructor. After college, he worked as a software engineer for
the Kansas State Legislature for three years before spending the next five years teaching
high school kids how to write code and make video games. As a teacher, he helped many
young aspiring game developers achieve beyond what they ever thought possible,
including winning the SkillsUSA National Championship for video game development in
2019 with a virtual reality game made in Unity. Andrew lives in Washington with his wife,
Jessica, and daughters, Alice and Ada.

Adam Brzozowski is an experienced software engineer who develops games and client
applications. Working with Unity, Unreal Engine, C++, Swift, and Java, he finds the right
solution for each project.

Packt is searching for authors like you


If you're interested in becoming an author for Packt, please visit authors.packtpub.com
and apply today. We have worked with thousands of developers and tech professionals,
just like you, to help them share their insight with the global tech community. You can
make a general application, apply for a specific hot topic that we are recruiting an author
for, or submit your own idea.
Table of Contents
Preface 1
Chapter 1: Getting to Know Your Environment 7
Technical requirements 8
Getting started with Unity 2020 9
Using macOS 15
Creating a new project 17
Navigating the editor 18
Using C# with Unity 20
Working with C# scripts 20
Introducing the Visual Studio editor 22
Time for action – opening a C# file 22
Beware of naming mismatches 25
Syncing C# files 25
Exploring the documentation 26
Accessing Unity's documentation 26
Time for action – opening the Reference Manual 26
Time for action – using the Scripting Reference 27
Locating C# resources 29
Time for action – looking up a C# class 29
Summary 30
Pop quiz – dealing with scripts 31
Chapter 2: The Building Blocks of Programming 32
Defining variables 33
Names are important 34
Variables act as placeholders 34
Time for action – creating a variable 35
Time for action – changing a variable's value 37
Understanding methods 38
Methods drive actions 38
Methods are placeholders too 39
Time for action – creating a simple method 40
Introducing classes 41
A common Unity class 41
Classes are blueprints 42
Working with comments 43
Practical backslashes 43
Multi-line comments 43
Time for action – adding comments 44
Putting the building blocks together 45
Table of Contents

Scripts become components 45


A helping hand from MonoBehavior 46
Hero's trial – MonoBehavior in the Scripting API 47
Communication among classes 47
Summary 48
Pop quiz – C# building blocks 48
Chapter 3: Diving into Variables, Types, and Methods 49
Writing proper C# 50
Debugging your code 51
Declaring variables 52
Type and value declarations 52
Type-only declarations 53
Using access modifiers 54
Choosing a security level 54
Time for action – making a variable private 55
Working with types 55
Common built-in types 56
Time for action – playing with different types 57
Time for action – creating interpolated strings 58
Type conversions 59
Inferred declarations 60
Custom types 60
Types roundup 60
Naming variables 61
Best practices 61
Understanding variable scope 62
Introducing operators 64
Arithmetic and assignments 64
Time for action – executing incorrect type operations 66
Defining methods 67
Basic syntax 67
Modifiers and parameters 68
Time for action – defining a simple method 69
Naming conventions 70
Methods are logic detours 70
Specifying parameters 71
Time for action – adding method parameters 72
Specifying return values 73
Time for action – adding a return type 73
Using return values 74
Time for action – capturing return values 74
Hero's trial – methods as arguments 75
Dissecting common Unity methods 76
The Start method 76
The Update method 77

[ ii ]
Table of Contents

Summary 78
Pop quiz – variables and methods 78
Chapter 4: Control Flow and Collection Types 79
Selection statements 80
The if-else statement 80
Basic syntax 80
Time for action – thieving prospects 83
Using the NOT operator 85
Nesting statements 86
Evaluating multiple conditions 87
Time for action – reaching the treasure 88
The switch statement 90
Basic syntax 90
Pattern matching 91
Time for action – choosing an action 91
Fall-through cases 92
Time for action – rolling the dice 92
Pop quiz 1 – if, and, or but 94
Collections at a glance 94
Arrays 94
Basic syntax 95
Indexing and subscripts 96
Range exceptions 96
Lists 97
Basic syntax 97
Time for action – party members 98
Common methods 99
Dictionaries 100
Basic syntax 100
Time for action – setting up an inventory 101
Working with dictionary pairs 102
Pop quiz 2 – all about collections 103
Iteration statements 103
For loops 104
Time for action – finding an element 105
foreach loops 107
Looping through key-value pairs 108
Hero's trial – finding affordable items 109
while loops 109
Time for action – tracking player lives 110
To infinity and beyond 111
Summary 112
Chapter 5: Working with Classes, Structs, and OOP 113
Defining a class 114
Basic syntax 114
Time for action – creating a character class 114
Instantiating class objects 115

[ iii ]
Table of Contents

Time for action – creating a new character 115


Adding class fields 116
Time for action – fleshing out character details 117
Using constructors 118
Time for action – specifying starting properties 119
Declaring class methods 120
Time for action – printing out character data 120
Declaring structs 122
Basic syntax 122
Time for action – creating a weapon struct 123
Understanding reference and value types 124
Reference types 124
Time for action – creating a new hero 125
Value types 126
Time for action – copying weapons 126
Integrating the object-oriented mindset 127
Encapsulation 128
Time for action – adding a reset 128
Inheritance 129
Base constructors 130
Time for action – calling a base constructor 130
Composition 131
Polymorphism 132
Time for action – functional variations 132
OOP roundup 133
Applying OOP in Unity 134
Objects are a class act 134
Accessing components 136
Basic syntax 136
Time for action – accessing the current transform component 137
Time for action – finding components on different objects 138
Drag and drop 139
Time for action – assigning variables in Unity 140
Summary 141
Pop quiz – all things OOP 141
Chapter 6: Getting Your Hands Dirty with Unity 142
A game design primer 143
Game design documents 143
The Hero Born one-page 144
Building a level 145
Creating primitives 145
Time for action – creating a ground plane 146
Thinking in 3D 147
Materials 149
Time for action – changing the ground color 150
White-boxing 151

[ iv ]
Table of Contents

Editor tools 152


Hero's trial – putting up drywall 154
Keeping the hierarchy clean 154
Time for action – using empty objects 155
Working with prefabs 156
Time for action – creating a turret 156
Time for action – updating the prefab 158
Time for action – finishing the level 159
Hero's trial – creating a health pickup 160
Lighting basics 161
Creating lights 162
Light component properties 163
Animating in Unity 164
Creating clips 164
Time for action – creating a new clip 165
Recording keyframes 167
Time for action – spinning animation 168
Curves and tangents 170
Time for action – smoothing the spin 171
The particle system 173
Time for action – adding sparkle effects 173
Summary 175
Pop quiz – basic Unity features 175
Chapter 7: Movement, Camera Controls, and Collisions 176
Moving the player 177
Player setup 178
Time for action – creating the player capsule 178
Understanding vectors 179
Getting player input 181
Time for action – player locomotion 183
Adding a following Camera 186
Time for action – scripting camera behavior 186
Working with Unity physics 189
Rigidbody components in motion 191
Time for action – accessing the Rigidbody component 191
Time for action – moving the Rigidbody component 193
Colliders and collisions 195
Time for action – picking up an item 196
Using Collider triggers 198
Time for action – creating an enemy 199
Time for action – capturing trigger events 199
Hero's trial – all the prefabs! 202
Physics roundup 202
Summary 203
Pop quiz – player controls and physics 203
Chapter 8: Scripting Game Mechanics 204

[v]
Table of Contents

Adding jumps 205


Introducing enumerations 205
Underlying types 206
Time for action – pressing the spacebar to jump! 207
Working with layer masks 209
Time for action – setting object layers 209
Time for action – one jump at a time 211
Shooting projectiles 214
Instantiating objects 214
Time for action – creating a projectile prefab 215
Time for action – adding the shooting mechanic 216
Managing GameObject buildup 219
Time for action – destroying bullets 219
Creating a game manager 220
Tracking player properties 220
Time for action – creating a game manager 221
The get and set properties 222
Time for action – adding backing variables 223
Time for action – updating item collection 225
Adding player polish 227
Graphical UI 227
Time for action – adding UI elements 228
Win and loss conditions 231
Time for action – winning the game 231
Using directives and namespaces 234
Time for action – pausing and restarting 234
Summary 236
Pop quiz – working with mechanics 236
Chapter 9: Basic AI and Enemy Behavior 237
Navigating in Unity 238
Navigation components 238
Time for action – setting up the NavMesh 239
Time for action – setting up enemy agents 240
Moving enemy agents 242
Procedural programming 243
Time for action – referencing the patrol locations 243
Time for action – moving the enemy 246
Time for action – patrolling continuously between locations 248
Enemy game mechanics 250
Seek and destroy 251
Time for action – changing the agent's destination 251
Time for action – lowering player health 252
Time for action – detecting bullet collisions 254
Time for action – updating the game manager 256
Refactoring and keeping it DRY 258
Time for action – creating a restart method 258

[ vi ]
Table of Contents

Hero's trial – refactoring win/lose logic 259


Summary 260
Pop quiz – AI and navigation 260
Chapter 10: Revisiting Types, Methods, and Classes 261
Access Modifier redux 262
Constant and read-only properties 262
Using the static keyword 263
Time for action – creating a static class 263
Methods redux 265
Overloading methods 265
Time for action – overloading the level restart 266
Ref parameters 267
Time for action – tracking player restarts 268
Out parameters 269
OOP redux 270
Interfaces 270
Time for action – creating a manager interface 271
Time for action – adopting an interface 272
Abstract classes 274
Class extensions 276
Time for action – extending the string class 276
Time for action – using an extension method 277
Namespace redux 279
Type aliasing 279
Summary 280
Pop quiz – leveling up 280
Chapter 11: Introducing Stacks, Queues, and HashSets 281
Introducing stacks 282
Basic syntax 282
Time for action – storing collected items 283
Popping and peeking 285
Time for action – the last item collected 285
Common methods 286
Working with queues 288
Basic syntax 288
Adding, removing, and peeking 289
Common methods 289
Using HashSets 290
Basic syntax 290
Performing operations 291
Summary 293
Pop quiz – intermediate collections 293
Chapter 12: Exploring Generics, Delegates, and Beyond 294
Introducing generics 295

[ vii ]
Table of Contents

Generic objects 295


Time for action – creating a generic collection 296
Generic methods 297
Time for action – adding a generic item 298
Constraining type parameters 300
Time for action – limiting generic elements 301
Delegating actions 301
Basic syntax 301
Time for action – creating a debug delegate 302
Delegates as parameter types 304
Time for action – using a delegate argument 304
Firing events 305
Basic syntax 306
Time for action – creating an event 306
Handling event subscriptions 307
Time for action – subscribing to an event 308
Handling exceptions 310
Throwing exceptions 310
Time for action – checking negative scene indexes 311
Using try-catch 312
Time for action – catching restart errors 313
Design pattern primer 316
Common game patterns 316
Summary 317
Pop quiz – intermediate C# 318
Chapter 13: The Journey Continues 319
Scratching the surface 320
Remembering your object-oriented programming 321
Approaching Unity projects 321
Unity features we didn't cover 322
Next steps 322
C# resources 323
Unity resources 323
Unity certifications 324
Hero's trial – putting something out into the world 324
Summary 325
Pop Quiz Answers 326
Other Books You May Enjoy 331
Index 334

[ viii ]
Preface
Unity is one of the most popular game engines in the world, catering to amateur hobbyists,
professional AAA studios, and cinematic production houses. While mainly considered a 3D
tool, Unity has a host of dedicated features that support everything from 2D games and
virtual reality to post-production and cross-platform publishing.

Developers love its drag-and-drop interface and built-in features, but it's the ability to write
custom C# scripts for behaviors and game mechanics that really take Unity the extra mile.
Learning to write C# code might not be a huge obstacle to a seasoned programmer with
other languages under their belt, but it can be daunting for those of you who have no
programming experience. That's where this book comes in, as I'll be taking you through the
building blocks of programming and the C# language from scratch, all while building a fun
and playable game in Unity.

Who this book is for


This book was written primarily for those of you who don't have any experience with the
basic tenets of programming or the C# language. If you're a competent novice or seasoned
programmer coming from another language, or even C#, but need to get hands-on with
game development in Unity, then this is where you need to be.

What this book covers


Chapter 1, Getting to Know Your Environment, gets you started with the Unity installation
process, the main features of the editor, and finding documentation for both C# and Unity-
specific topics. We'll also go through creating C# scripts from inside Unity and take a look
at the Visual Studio application, where all our code editing will take place.

Chapter 2, The Building Blocks of Programming, begins by laying out the atomic-level
concepts of programming, giving you the opportunity to relate variables, methods, and
classes to situations in everyday life. From there, we move on to simple debugging
techniques, proper formatting and commenting, and a look at how Unity turns C# scripts
into components.
Preface

Chapter 3, Diving into Variables, Types, and Methods, takes a deeper look at variables. This
includes C# data types, naming conventions, access modifiers, and everything else
you'll need for the foundation of a program. We'll also go over how to write methods,
incorporate parameters, and use return types effectively, ending with an overview of
standard Unity methods belonging to the MonoBehavior class.

Chapter 4, Control Flow and Collection Types, introduces the common approaches to making
decisions in code, consisting of the if...else and switch statements. From there, we
move on to working with arrays, lists, and dictionaries, and incorporating iteration
statements for looping through collection types. We end the chapter with a look at
conditional looping statements and a special C# data type called enumerations.

Chapter 5, Working with Classes, Structs, and OOP, details our first contact with constructing
and instantiating classes and structs. We'll go through the basic steps of creating
constructors, adding variables and methods, and the fundamentals of subclassing and
inheritance. The chapter will end with a comprehensive explanation of object-oriented
programming and how it applies to C#.

Chapter 6, Getting Your Hands Dirty with Unity, marks our departure from C# syntax into
the world of game design, level building, and Unity's featured tools. We'll start by going
over the basics of a game design document and then move on to blocking out our level
geometry and adding lighting and a simple particle system.

Chapter 7, Movement, Camera Controls, and Collisions, explains different approaches to


moving a player object and setting up a third-person camera. We'll discuss incorporating
Unity physics for more realistic locomotion effects, as well as how to work with collider
components and capture interactions within a scene.

Chapter 8, Scripting Game Mechanics, introduces the concept of game mechanics and how to
effectively implement them. We'll start by adding a simple jump action, create a shooting
mechanic, and build on the previous chapters' code by adding logic to handle item
collection.

Chapter 9, Basic AI and Enemy Behavior, starts with a brief overview of artificial intelligence
in games and the concepts we will be applying to Hero Born. Topics covered in this chapter
will include navigation in Unity, using the level geometry and a navigation mesh, smart
agents, and automated enemy movement.

Chapter 10, Revisiting Types, Methods, and Classes, takes a more in-depth look at data types,
intermediate method features, and additional behaviors that can be used for more complex
classes. This chapter will give you a deeper understanding of the versatility and breadth of
the C# language.

[2]
Preface

Chapter 11, Introducing Stacks, Queues, and HashSets, dives into intermediate collection
types and their features. Topics covered in this chapter include using Stacks, Queues, and
HashSets and the different development scenarios that each is uniquely suited for.

Chapter 12, Exploring Generics, Delegates, and Beyond, details intermediate features of the C#
language and how to apply them in practical, real-world scenarios. We'll start with an
overview of generic programming and progress to concepts such as delegation, events, and
exception handling. The chapter will end with a brief discussion of common design
patterns and set you up for further study.

Chapter 13, The Journey Continues, reviews the main topics you've learned throughout the
book and leaves you with resources for further study in both C# and Unity. Included in
these resources will be online reading material, certification information, and a host of my
favorite video tutorial channels.

To get the most out of this book


The only thing you need to get the most from your upcoming C# and Unity adventure is a
curious mind and a willingness to learn. Having said that, doing all the Time for
Action, Heroes Trial, and Quiz sections is a must if you hope to cement the knowledge
you're learning. Lastly, revisiting topics and entire chapters to refresh or solidify your
understanding before moving on is always a good idea. There is no sense in building a
house on an unstable foundation.

You'll also need a current version of Unity installed on your computer – 2020 or later is
recommended. All code examples have been tested with Unity 2020.1 and should work
with future versions without issues.

Software/hardware covered in the book


Unity 2020.1 or later
Visual Studio 2019 or later
C# 8.0 or later

Before starting, check that your computer setup meets the Unity system requirements
at https:/​/​docs.​unity3d.​com/​2019.​1/​Documentation/​Manual/​system-​requirements.
html. These are for Unity 2019 but hold true for 2020 and above.

[3]
Preface

Download the example code files


You can download the example code files for this book from your account at
www.packt.com. If you purchased this book elsewhere, you can visit
www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

1. Log in or register at www.packt.com.


2. Select the Support tab.
3. Click on Code Downloads.
4. Enter the name of the book in the Search box and follow the onscreen
instructions.

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-​8-​by-​Developing-​Games-​with-​Unity-​2020. In case there's
an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available
at https:/​/​github.​com/​PacktPublishing/​. Check them out!

Download the color images


We also provide a PDF file that has color images of the screenshots/diagrams used in this
book. You can download it
here: https://static.packt-cdn.com/downloads/9781800207806_ColorImages.pdf.

Conventions used
There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in the text, database table names, folder names,
filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here
is an example: "Select the Materials folder."

[4]
Preface

A block of code is set as follows:


public string firstName = "Harrison";

When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
accessModifier returnType UniqueName(parameterType parameterName) {
method body
}

Bold: Indicates a new term, an important word, or words that you see on screen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example:
"Click on Create | 3D Object | Capsule from the Hierarchy panel."

Warnings or important notes appear like this.

Tips and tricks appear like this.

Get in touch
Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book
title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit www.packtpub.com/support/errata, selecting your book,
clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we
would be grateful if you would provide us with the location address or website name.
Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in,
and you are interested in either writing or contributing to a book, please visit
authors.packtpub.com.

[5]
Preface

Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

[6]
1
Getting to Know Your
Environment
Pop culture has taught us that computer programmers are often outsiders, lone wolves, or
geeky hackers who possess extraordinary mental gifts for algorithmic thought, little social
IQ, and the odd anarchic bent. While this is not the case, there is something to the idea that
learning to code fundamentally changes the way you look at the world. The good news is
that your naturally curious mind will quickly adapt to this new way of thinking and may
even come to enjoy it.

You already use analytical skills in your everyday life that translate to programming –
you're just missing the right language and syntax to map those life skills into code. You
know your age, right? That's a variable. When you cross the street, I presume you look
down the road in both directions before stepping off the curb like the rest of us. That's
evaluating different conditions, or what we call control flow in programming parlance.
When you look at a can of pop, you instinctively identify that it has certain properties such
as shape, weight, and contents. That's a class object! You get the idea.
Getting to Know Your Environment Chapter 1

With all that real-world experience at your fingertips, you're more than ready to cross over
into the realm of programming. You'll need to know how to set up your development
environment, work with the applications involved, and know exactly where to go when
you need help. To that end, we're going to begin our adventure delving into C# by covering
the following topics:

Getting started with Unity


Working with Visual Studio
Using C# with Unity
Exploring the documentation

Let's get started!

Technical requirements
Sometimes, it's easier to start with what a thing isn't, rather than what it is. The main goal
of this book isn't to learn the vast ins and outs of the Unity game engine or all of game
development. By necessity, we'll cover these topics at a basic level here at the beginning of
our journey, and in more detail in Chapter 6, Getting Your Hands Dirty with
Unity. However, these topics are simply to provide a fun, accessible way for us to learn the
C# programming language from the ground up.

Since this book is aimed at complete beginners to programming, if you have no previous
experience with either C# or Unity, you're in the right place! If you've had some experience
with the Unity Editor but not with programming, guess what? This is still the place to be.
Even if you've dabbled in a bit of C# mixed with Unity, but want to explore some more
intermediate or advanced topics, the later chapters of this book can provide you with what
you're looking for.

If you're an experienced programmer in other languages, feel free to skip


the beginner theory and dive right into the parts you're interested in, or
stick around and refresh your fundamentals.

[8]
Getting to Know Your Environment Chapter 1

Getting started with Unity 2020


If you don’t have Unity installed already, or are running an earlier version, you'll need to
do a little setup. Follow these steps:

1. Head over to https:/​/​www.​unity.​com/​.


2. Select Get Started (shown in the following screenshot), which will take you to
the Unity store page:

If the Unity home page looks different for you than what you can see in
the preceding screenshot, you can go directly to https:/​/​store.​unity.
com.

Don't feel overwhelmed by this – you can get Unity completely free!

[9]
Getting to Know Your Environment Chapter 1

3. Click the Individual tab and select the Personal option on the left. The other paid
options offer more advanced functionality and services subscribers, but you can
check these out on your own:

After selecting the personal plan, you'll be asked if you're a first-time or returning user.

[ 10 ]
Getting to Know Your Environment Chapter 1

4. Select Start here under First-time Users:

5. Select Agree and download to get your copy of Unity Hub:

[ 11 ]
Getting to Know Your Environment Chapter 1

Once the download is complete, follow these steps:

1. Open up the package (by double-clicking it).


2. Accept the user agreement.
3. Follow the installation instructions. When you get the green light, go ahead and
fire up the Unity Hub application! You'll see the following screen:

The newest version of Unity Hub has a wizard or getting started path
when you first open the application. If you'd like to follow that, feel free.
The following steps show you how to start a new project without any help
from the application since that's only available on the first launch.

4. With Unity Hub open, switch to the Installs tab from the left-hand menu and
select ADD:

[ 12 ]
Getting to Know Your Environment Chapter 1

At the time of writing, Unity 2020 is still in its Alpha phase, but you should be able to select
a 2020 version from the Latest Official Releases list:

[ 13 ]
Getting to Know Your Environment Chapter 1

You won't need any specific platform modules to follow along with future examples, so go
ahead and leave this as-is. If you do want to add them at any time, you can click the
More button (three-dot icon) at the upper right of any version in the Installs window:

When the installation is complete, you'll see a new version in your Installs panel, as
follows:

[ 14 ]
Another random document with
no related content on Scribd:
a pair of sharp eyes protrude, and short legs carry his wobbly body
about. Is it not only natural that everyone of the household will make
much over him, if they are normal human beings? It will be noted
that even though this bit of dog flesh is still less than twelve weeks
old, how readily he will make up with them. A young puppy, still
unaccustomed to the rebuffs of the world and the “slings and arrows”
of canine fortune has confidence in all whom he encounters. His
perceptions are keen, however, and he will soon learn that there are
some or at least one in the family to whom he may attach himself as
his real master or mistress, and therefore this should be the person
to teach him his early knowledge of household etiquette. It should be
this person, also, who imposes upon himself or herself the duty of
feeding the puppy. Of course this is not entirely essential, but if it is
left to one person, it may be generally taken for granted that the
youngster will be fed regularly and not too much. When the entire
household looks after the feeding, the chances are that he will be too
well cared for, and too frequent feeding is one of the banes of dog-
keeping. An overabundance of food is more dangerous than too
little, although I am no advocate of the starvation plan.
The matter of feeding will be taken up in the next chapter, so let us
pass on to the puppy’s early education. In the first place, if a
secluded nook has been decided upon where he is to sleep nights,
he should be introduced to this the very first night. To begin by
pampering him is only deferring a duty that must be done sooner or
later. Assuming that he has a basket or box in the kitchen, the last
thing before he is put to bed, it is well to feed him. At this early stage
the last feed in the evening may consist of milk and bread, or any of
the puppy meals with milk poured over. Put him in his bed, turn out
the lights and leave him. The chances are that he will not remain in
his bed, but come out and go near the door communicating with the
other apartments of the house, and whine. Go to him, chide him and
put him back in his bed, commanding him to lie down. This, of
course, he will not understand at once and it is quite likely that for
the first three or four nights he will make life hideous by his howling.
However, it is surprising how soon he will learn that he must make
the best of a new condition, for to him it is an entirely new situation in
life. Coming from his litter mates in a home where he has been
accustomed to the association of his mother, his brothers and
sisters, it is quite natural that the nostalgia, or homesickness, should
oppress him. Be firm, however, and make him “stay put” not only the
first night, but every night and he will soon be broken of the night
howling.
All dogs are naturally cleanly in their habits and it will be noticed that
even very young puppies will go some distance away from their
nests to obey the call of nature, consequently when the puppy is
brought into the home, correct habits may soon be taught. The
principal care is to catch him in the act and then remove him
summarily from the house. If he persists, a very slight tap or two and
a word of reprimand as he is being banished may assist quite
materially in making him understand. Some breeds are more easily
broken than others. I have found Airedales and cocker spaniels very
easy to break of uncleanly habits. Pointers and setters require more
time, but on the whole, most of the medium-sized breeds can be
broken very readily. The new owner should not lose sight of the fact,
however, that he must not be too severe. Firmness and prompt
action are the principal requisites that must be kept in mind in
breaking a puppy, but brutality never succeeds.
One of the earliest lessons that any young dog should be taught is
his name. This should be chosen as early as possible and whenever
the attention of the puppy is to be attracted, he should be called by
his name. All puppies will come to most anyone who will play with
them. On such occasions it is well to give the youngster his first
lessons. Call him to you, using the name you have selected. If he
comes to you, pet and fondle him, repeating the name meanwhile,
and reward him with a choice morsel to eat. Thus, in a very short
time the dog will learn to come promptly when called. Teaching to
whistle may be done in much the same manner, either in a large
room or in a yard. Blow the whistle when he is some distance from
you and call his name immediately after. He will be attracted, but will
come at the sound of his name and not the whistle. By frequent
repetition, however, he will soon learn to associate the blast of the
whistle with the verbal command and come to you promptly,
especially if at first he is rewarded with the ever-present choice
morsel.
If your dog happens to be a spaniel or one to be used as a sporting
companion, retrieving is an accomplishment which is a very excellent
one. Any dog will run after a ball if it is thrown from him after his
attention is first attracted. If one begins when the pupil is still quite
young he may be taught to become a perfect retriever through the
“Play Method,” as described in my book, “The Working Dog and His
Education.” When the ball is thrown the command should be given to
“Fetch!” The puppy will get the ball nine times out of ten, but he is
likely to run away with it and toss it about in play. He should be
induced to bring it to you or you must go to him, bring him to where
you were standing when the ball was thrown and gently take it out of
his mouth, repeating the word “Fetch!” As in the other lessons,
reward him with a bite to eat. A little of this play every day will make
him enjoy this pastime and in the end he will become a retriever. He
may also be taught to retrieve from water in the same manner,
although at first the ball should be thrown into the water only far
enough so that the puppy need but get his feet wet in retrieving it. It
may be thrown out farther and farther as the pupil progresses and in
the end he will enjoy this as much as land retrieving, especially if he
is a dog of the spaniel varieties. Airedales are also easily taught to
become perfect retrievers.
Another lesson which all dogs should learn is to remain at heel. First
it is necessary to teach them to lead. Put a collar on the puppy and
allow it to remain a day or two before going further. When he is
accustomed to this, attach the lead and call him to you. He will likely
pull back or buck jump a few times; keep a tight line and allow him to
go as far as he likes. When he becomes passive, call him to you and
draw in the lead. He may pull back or he may be frightened, but pull
him to you and then pet him and reward him with a bit to eat. He will
soon learn to lead.
After he once leads well then take him out with you on the street or
in the park. If he pulls ahead of you draw him back and give the
command “Heel!” He may remain behind for a moment, but dart
ahead again in a moment when he thinks you off guard. Check him
up and put him back of you once more with the same command to
“Heel!” If he goes along in this manner, fairly well after a few lessons,
you have accomplished the first step. Later it may be necessary to
carry a light switch which should be used on every occasion when
the dog attempts to forge ahead. Only a light tap on the nose is
necessary, but as it is given the command to heel should also be
uttered. In a short time the dog should be taken out without the cord
and kept at heel, but if he becomes unruly and does not remain in
his position the lead should be immediately snapped into the ring of
the collar and he should be given a few more lessons of the earlier
kind. Eventually he will understand that he must remain behind his
master until the command is given to “Go!” or “Hie on!” and this latter
command he will obey without much teaching, for it is the natural
inclination of all dogs to run on ahead of their masters, and they will
be prompt to take advantage of the permission to do so.
For fuller lessons on breaking, I would suggest that the reader
procure a copy of my former book, “The Working Dog and His
Education.”
CHAPTER VI.
The Food Question—When to Feed—Frequency
of Feeding—Water.

With but one dog in the household or on the premises, the question
of food is not a serious one. The scraps from the table of a family of
four should be sufficient to supply the entire ration of the dog,
although occasionally it is advisable to give him a change in the way
of scraps of raw beef, large, soft bones to gnaw upon, and by variety
it might also be well, say once a week, to procure the meat or
trimmings at your butcher’s out of which a broth may be made. This
is always a wholesome diet, especially if it is poured over stale
bread, dog biscuits or any of the bread stuffs that cannot be used on
the table.
First of all let me disabuse the reader of the old theory that meat is
injurious for the dog. Taking the race as a whole, meat should form
the principal diet. The dog is a naturally carnivorous animal and even
though he has been under domestication for thousands of years his
organs of mastication and digestion have undergone only a very
slight, if indeed, any change. With this in mind, the dog owner is
enabled to feed intelligently. Naturally, change of environment from
his wild state has made conditions different; he does not obtain the
amount of exercise that his wild ancestors did, ranging and roaming
about the country in search of their daily sustenance, consequently
he cannot be fed entirely the same, but nevertheless the idea which
through some unknown way became prevalent years ago that meat
is injurious to dogs and likely to cause disease is entirely erroneous.
The principal point to keep before one is the quantity of food and the
frequency of feeding. A dog which obtains considerable exercise in
the way of hunting, must have more meat than one that is exercised
only an hour or two each day. This is but natural; the man whose
profession keeps him indoors does not require the same substantial
food of the one who labors in the fields all day, and so it is with the
dog. Ordinary intelligence should teach proper discretion in this
respect.
Table scraps usually consist of all the necessary concomitants to a
good ration. Bits of meat, bread crusts, gravies, vegetables, etc., all
go to make up the waste from the table in any ordinary family.
Bones, if they are large ones, may be fed, but bones from fish,
poultry or small game should be eliminated if for no other reason but
the possibility of their causing trouble in the intestinal canal. If one
does not believe what trouble this may produce let him take the leg
bone of a chicken or lamb, place them on a stone and strike them a
sharp blow with a hammer. He will see at once that they are crushed
into a hundred tiny splinters. One can readily imagine what havoc
this may do if they should lodge in the stomach or intestines of a
dog. Perhaps one might feed these bones to a dog throughout his
entire life without ill results, but on the other hand, trouble might
ensue, hence to be on the safe side, it is better to take no chances.
Vegetables make a good bulk food, but they should be fed very
sparingly, and then only in connection with the other food. There is
little nutriment in vegetables for a dog; potatoes are of no value and
are more harmful than beneficial and the idea that dogs must be fed
garlic, tomatoes, onions and the like has been exploded long ago. A
very little of these in the regular food is passable, but do not attempt
to make a vegetarian of your dog. Corn meal, in its place, is well
enough fed occasionally, but as a regular food it is harmful,
especially in summer, as it causes skin irritations, because it is too
heating. Oat meal is some better, and rice, perhaps, the best of all,
but any of these foods should be fed only occasionally. Some
breeds, such as Yorkshire terriers, Maltese and the like do very well
with little meat and some say they should not have it at all, but even
this is questionable.
In large kennels it is well to cook one’s own food or make a bread
composed of unbolted wheat, a little rice, meat and a few well
cooked vegetables, the whole to be thoroughly cooked and then
baked into a bread in a slow oven which will cook it through and
through so that it will keep for a long time, but the owner of one dog
may as well dismiss this as unnecessary. To summarize: feed what
the family table offers, procure meat from your butcher occasionally,
for the broth and bones previously referred to, and do not overlook
the raw meat, which should be shredded or chopped finely and fed
three or four times a week in small quantities, for young dogs, but in
larger portions for grown ones. It is also well to obtain large bones
with the meat still clinging to them. Dogs love to tear the meat from
the bones and they also obtain considerable satisfaction in gnawing
the bones. Even puppies three months old and under may be fed
raw meat in small quantities to good advantage, and from personal
experience I have found that puppies thus fed will thrive better than
those who obtain little or none of this kind of diet.
For very young puppies the natural diet is milk, hence when you
obtain your new dog, assuming that he is three months old or under,
see that he obtains an abundance of this, but do not compel him to
live on a milk and bread diet entirely. Feed him a dish of this in the
morning; and it might be well to give him another small feed of this
about ten o’clock, then again at two and so on, until he is fed about
five times during the day, but some of the meals should consist of
broth and cooked meat, with an occasional feed of raw flesh.
Puppies, as they grow older, should be fed less often, and at four
months, three meals a day are sufficient. At this stage, the first meal
in the morning may consist of milk and stale bread, but the following
ones may be of table scraps or the broth made from the meat
obtained from the butcher, poured over stale bread of biscuits, giving
with the liquid also a sufficient quantity of the meat. At a year old the
dog may be fed as any older dog is fed.
The question of frequency of feeding matured dogs has been much
discussed. Many kennels feed but once daily and that meal is given
in the evening. This should consist of as much in quantity as the dog
will eat. The more humane method for grown dogs, however, is to
feed a light meal in the morning and the heavy one in the evening.
Most dogs thrive well on this, provided they obtain a sufficient
amount of meat to keep their natural desire for flesh food satisfied.
The dog owner will soon learn how to use discretion in feeding and
obtain best results, but those who wish to go further into this food
question are cited to my previous book, “Practical Dog Keeping For
the Amateur.”
As to water, it must be borne in mind that the dog requires water at
all times of the day or night and a vessel containing pure, fresh water
should always be accessible.
CHAPTER VII
Exercise—Grooming—Washing.

While we all recognize the importance of good food as being


conducive to a dog’s well being, many overlook the fact that
exercise, grooming and washing are almost equally essential. This is
particularly true of exercise. No matter how well a dog is fed, no
matter what his care may be otherwise, he will become sluggish and
out of sorts if he is unable to obtain a sufficient amount of daily
exercise and the more that falls to his lot, the less liable is he to
disease, for it is a well-known fact among human beings that
exercise is one of the essentials of life and by the same token this is
so of the dog. Without exercise the animal will not assimilate his food
and while the digestive organs will perform their functions for a long
time, eventually they will do so under protest, for the food taken into
the system is not properly oxidized, drainage is impeded and the
general sewerage system becomes faulty. No drugs will regulate this
condition of affairs effectively and in time the result of this sedentary
life begins to show in the dog’s eyes, his coat, and even his nerves.
Mange and various eczematous diseases are also likely to appear,
and many other disorders are likely to follow. Consequently, if one
takes upon himself the responsibility of keeping a dog he must see
to his exercise as religiously as he does to his food.
The question may be asked, how much exercise must a dog have in
order to keep him in good condition? To this no defined rule can be
laid down, for dogs, like humans, vary and one must be governed
accordingly. Most young puppies, because of their natural
exuberance of spirits, generally move about sufficiently of their own
volition, and thus keep in good condition by this very natural process,
but as the dog grows older he is not so prone to run and play, and
therefore must be encouraged. This exercise, it is scarcely
necessary to say, should be given in the open. If the owner of a dog
has a back yard where the dog may run and play out in the air and
the sunshine, the question of exercise is not a serious one, but
people who live in restricted quarters will find it more of a problem.
If one has access to a vacant lot, a common, a park, or other open
space where he may allow his dogs to run unmolested, always
provided he is at hand to watch them, then the question settles itself,
but where this is not possible there is only one other way and that is
to take the dog out on lead, walking him from one to three hours,
according to the breed and the requirements of the individual, for as
previously stated, some dogs require more exercise than others. It
should not be forgotten that a dog running at large covers five or six
times the amount of ground that he could possibly cover while on
lead, and this must be taken into consideration. Naturally this
requires time, but one may always find a spare hour or two mornings
and evenings that may be utilized in this manner, and thus owner as
well as dog obtains good, healthful recreation.
Another good way to exercise dogs in summer is to take them to a
pond or river where they may swim about in the water, for nothing
brings all the muscles into play better than swimming. Nearly all
dogs can be taught to take to water, and some of the breeds as for
instance Airedales, the spaniel varieties, and also pointers and
setters, dearly love this diversion. After disporting in the water for an
hour or so, if a plot of grass can be found nearby where the dogs can
roll and dry themselves, it will not only add to the enjoyment of
master and dog, but will tend to keep the animals’ coats clean.
Another point that should be borne in mind is, all dogs should be
allowed to exercise in a manner that is compatible with their natural
habits. For instance, a beagle should be taken to the open and
allowed to hunt rabbits, a bird dog should be turned loose in the
open fields and terriers of every description should be given the
opportunity to dig for rats, mice or other “varmints.” If this cannot be
done every day, the dogs should be given this opportunity at least
once a week, especially during the season when this is feasible.
Summarizing, the owner must always bear in mind that a certain part
of the day his dog must be allowed the air and the sunshine. Even in
winter when there is little sunshine, or on rainy days, the dog will
enjoy being out and free for a short time.
Grooming is another very important essential to the welfare of the
dog. Every dog, no matter whether he is short or long-coated, should
be brushed at least once daily and by brushing is meant good,
vigorous friction. For the short-haired varieties a short-bristled brush
or a hound glove are the proper implements, and for the long-coated
breeds a brush with stiff bristles from one and one-half to two inches
long, is very useful. After this brushing, rubbing with the hand will put
a polish on the coat that is described by fanciers as “cherry ripe.”
Wire-coated terriers require some special treatment to keep their
coats in show shape, but ordinary brushing daily and plucking of
superfluous hair occasionally, will always tend to keep them
presentable for every-day life. Not only is this daily grooming
essential to keep the dog’s coat free from soil and filth, but it tends to
keep the blood in circulation, and to ward off skin troubles and also
parasites, which despite precautions, will sometimes take up their
quarters in the coats of the most genteel dogs.
During the winter it is seldom necessary to wash a dog provided he
is groomed daily, but in summer, a bath now and then is very
beneficial to most breeds, although owners of some show varieties
object to bathing their dogs on the ground that it softens the coat.
However, the average owner will do his dog little, if any harm, by
washing him once a week during the summer. To wash a medium-
sized dog, an ordinary tub or portable tin bath tub will be found
satisfactory. The soap used should be selected with some care.
Those soaps containing a large percentage of alkali are not advised,
nor are the highly scented kinds desirable. The old-fashioned pure
Castile is about as good as any and nearly all of the higher grades of
tar soaps are good. The latter not only produce profuse lather, but
possess excellent cleansing qualities and their ingredients have a
salutary effect on the skin and hair. There are also a number of good
dog soaps on the market, prepared especially for cleansing and
freeing the dog from vermin, both fleas and lice, should they exist. In
the summer nearly all dogs will acquire a certain amount of fleas and
it is well to use either the prepared dog soaps or some other
preparation that will kill the fleas. In this connection it might be said
that a good flea exterminator is any of the creosote preparations to
be used in one in fifty proportions. That is, to one part of the creosote
preparation use fifty parts of lukewarm water. Saturate the entire
coat and every part of the body with this preparation, but exercise
care not to get any of it in the eyes or mouth. After the dog has been
thoroughly saturated in this, he may be bathed with ordinary soap
and water. However, the water should always be lukewarm, even in
the warmest of weather. Not only will the lukewarm water cleanse
more thoroughly, but it will not be so much of a shock as when cold
water is used. For rinsing, clear water, a few degrees cooler may be
used. Be sure to dry thoroughly with towels, but rub the way the hair
lies. After drying with the towels the dog should be well brushed and
if the weather is the least cool he should not be allowed out of doors
for several hours after the bath unless he is kept in action. It is
always well to give the bath several hours after his meals, or just
before them; never directly after eating.
Smooth coated dogs are more easily bathed than the long-haired
varieties, as they can be dried very readily, but with the long-haired
breeds extreme care should be taken in the drying process and the
combing out of the coat. It is scarcely necessary to add that the
inside of the ears should be well dried. In washing a dog, always
begin with the head and work backward. The animal should be stood
in the tub and the water applied with a dipper which should be ready
at hand for the purpose.
For some breeds, such as Maltese and Yorkshire terriers many
prefer the egg shampoo to soap, although Yorkshires may be safely
washed with the suds of the soap, by making a lather and immersing
the animal in this. The formula for the egg shampoo is to break up
and lightly beat four eggs in each pint of water. Naturally, the egg
shampoo is beneficial for any dog no matter what the breed, but it
may be readily imagined how many eggs would be required to
shampoo four or five St. Bernards.
In the event that frequent washing causes the hair to become
unnaturally dry, a mixture of glycerine and water, one part in four, is
advisable. This may be applied before the dog is thoroughly dried
and the final hand rubbing will bring all the sheen, life and luster
back to the coat. Some kennel men use cocoa butter in place of the
glycerine. This is applied by dipping a comb into the cocoa butter
and going through the hair with this after the dog has been dried.
This should be followed by vigorous hand rubbing.
Reverting again to fleas, that bane of all dog owners, too much care
cannot be taken to prevent these pests from obtaining the upper
hand. The bedding must be frequently changed and the sleeping
places thoroughly cleansed, but the dog himself must be watched.
The creosote preparations (and there are many of them) are
considered the best exterminators and if used once a week in
summer, no dog should harbor fleas, provided his sleeping quarters
are clean. However, some might object to this preparation on toy
dogs and to those the following is recommended: Carbolic acid, one-
half ounce; laudanum, one ounce; bicarbonate of potassa, one dram;
water, one and one-half pints. Pour a small amount into a hand basin
and apply all over the body with a brush or sponge, rubbing it well
into the skin. To those who prefer a dry form of exterminator,
Dalmatian or Persian insect powder is recommended. The dog
should be placed on a newspaper, the powder dusted well into the
coat and allowed to remain for a few minutes, after which it should
be brushed out while the dog remains standing on the paper. After
this process is completed, roll up paper, powder, fleas and all and
burn.
CHAPTER VIII.
If Sickness Comes.

Where but one dog, or even two or three are kept in a home, the
danger of sickness is very small, especially if the behests as laid
down in the preceding chapters are followed. Dogs in the home are
not exposed like those which are kept in a kennel where new ones
are constantly coming in and going out. Nor is the danger of
contagious or infectious disease as great as when the dogs are
exhibited at bench shows. Nevertheless, the highly bred dog is a
fine-spun piece of mechanism and it is therefore best to know what
to do as first aid in case sickness does come. To the novice,
however, my advice is, send for the veterinarian, if a good one lives
in your vicinity, as soon as you notice something seriously wrong
with your dog. If no qualified canine practitioner is available, then
seek the advice of some dog expert, but do not resort to all manner
of dosing for dosing’s sake, as so many do, for in many cases too
much medicine has led to more serious consequences than the
illness itself.
The principal disorders that the one-dog owner is likely to encounter,
are probably distemper, worms, skin diseases, fits and other various
temporary stomach and intestinal ailments, most of which right
themselves by the administration of a dose of castor oil or some
other purgative.
Very frequently a dog will go off form due to overeating or perhaps
because of devouring something that was harmful, or possibly
because of lack of exercise. In most cases this is only temporary and
the animal will doctor himself, provided he has access to grass. Do
not be alarmed if your dog eats grass upon occasion, even though
he partakes of it copiously. He is simply finding in this green element
a nature remedy that will act as a conditioner. Fortunate is the canine
that has the opportunity to do this, for he is thus finding a home
remedy which is perhaps more effective than the most skilled
veterinarian might be able to prescribe.
Sometimes old dogs suffer from constipation and it is well,
occasionally, to put a little olive oil in their food, or even resort to a
purgative. One of the best ever-ready remedies I know of is equal
parts olive oil, cascara sagrada and castor oil. This may be mixed up
and kept on hand indefinitely as there is nothing in it that will spoil. If
your dog should go off his feed without showing any symptoms of
something more serious coming on, give him, if he is a dog of from
thirty to forty-five pounds, a tablespoonful of this night and morning
for four or five days, and he will soon come back to his natural form.
For smaller or larger dogs the dosage should be graded accordingly.
All dog owners, however, should know when a dog is coming down
with something serious. One of the most dreaded ailments is
distemper, a contagious disease which may be communicated either
by direct contact with a dog which has distemper, by being put in a
place that was recently occupied by a distempered animal, or by
associating with a dog which might be himself immune, but which
had recently come from a place where he was exposed. In this
manner such a dog is able to carry the disease even to some distant
locality. Thus many dogs have been subjected to disease through
their companions which were exhibited at bench shows, and which,
though immune themselves, carried it home to their kennel
companions.
First of all it should be said that the normal temperature of the dog is
from 100 to 100 1/2 degrees when taken under the forearm or inside
of the thigh. Taken per rectum it is one degree higher. This
temperature may vary some in the larger and the smaller breeds, but
it is the general average. If the dog appears listless, apathetic,
refuses to eat and possibly begins to sneeze or water at the eyes, if
his temperature has gone three or four degrees above normal, then
it may be taken for granted that he is in the first stages of distemper.
On the other hand, he may only show the dullness and the high
temperature; there may be no discharge from the eyes or nose, but a
dry, husky tell-tale cough may be noted. Any of these forms are the
symptoms of distemper and the victim should be isolated at once
and the first act should be to administer a liberal dose of castor oil. At
this stage I have found it very efficacious to give quinine and
hyposulphite of soda, each in two-grain doses, either together or one
following the other within half an hour, four times a day. The dog
must be placed in a warm and dry room and should not be allowed
to go out for anything. The room should be kept at a temperature of
seventy degrees, but must be ventilated by windows opening from
above so that there can be no draughts with which the victim will
come in contact. The disinfectant used should also be some dry
form, such as the various sanitary sawdust preparations that are on
the market. Any dampness in the room is detrimental to the patient.
The principal thing to remember in distemper is good care, for it will
be found more effective than medicine, whether given in serum form
or by mouth. The dog’s strength must be kept up and to this end
eggs, broth, and even finely chopped up raw beef in small quantities
will be beneficial. Some kennel men object to the beef, but
nevertheless many a dog will eat this where he refuses everything
else and certainly nothing is more nutritious than beef. Every
symptom must be combated as it arises and many complications are
likely to set in. One thing must always be kept in mind, and that is, to
make the dog take nourishment, for once he refuses to eat, then the
case is practically hopeless.
Those who prefer the serum treatment should begin giving it, as per
directions, subcutaneously, with hypodermic syringe. There are
several good serums or vaccines on the market, but the one that I
have had the most experience with is that put up by a Detroit
laboratory. This firm makes not only a curative vaccine, but one
known as a preventative. It is useless to give the prophylactic or
preventative after the dog has once been exposed. Rather await the
earliest developments and then begin with the curative and give the
six doses as per direction. Begin with bulb number one and follow up
at the intervals indicated until all have been given. In the meantime,
however, exercise the usual care in the way of even temperature in
the place where the patient is confined and in the matter of diet. This
is imperative, no matter what treatment is being used. The
prophylactic or curative treatment consists of three doses. It is also
given with hypodermic syringe, subcutaneously. It is well to keep this
serum on hand to use if one expects to show his dog or run him in
field trials, but the treatment should be given at least a month before
the time he is to appear in public. The success of this serum
treatment seems to be general, although many breeders have no
faith in it. This may be due to the fact that they begin too late or
failed to follow instructions. The treatment is supposed to combat all
symptoms that arise in the most virulent cases of distemper.
The worst complication of all distempers is that affecting the nervous
system; the brain and its membrane may become inflamed and fits
follow, or the spinal cord and its membranes are attacked, in which
event paralysis or chorea, or sometimes both occur. These can be
overcome, but it is a long drawn out and a very uncertain thing.
Generally, chorea occurs after the virulent phase of the disease is
passed and it is mostly due to too early exposure. The patient should
not be allowed to go out of doors or get excited in any way until the
temperature has been normal for at least ten days.
Common sense and good nursing win out more times than all the
medicine, but the complications as they arise must be combated. For
instance, the eyes must be looked after. The discharge should be
washed away frequently during the day with a warm boracic acid
solution by dissolving one teaspoonful of the boracic acid in half a
pint of warm water. The following lotion should be used afterward as
it will help keep the eyes clear:
Chinosol 3 grains
Water 6 ounces
As the dog recovers from the distemper and the eyes have that
opaque appearance so often noted, use an ointment made of 1 grain
yellow oxide of mercury mixed with one dram of vaseline. Drop a bit
about the size of a pea into the corner and rub well under the lids.
Sometimes red pustules will appear all over the underbody and
occasionally on all parts of the body. This should be treated with the
ordinary mange remedies. At other times the disease attacks the
bowels, which must then be looked after. Try bismuth in ten grain
doses for medium-sized dogs. If this does not stop the diarrhea, then
the following mixture might be effective:
Powdered Extract of Kino 1 dram
Powdered Ipecacuanha 8 grains
Powdered Opium 6 grains
Mix and divide into twelve pills.
Dose, from one-half to two pills, according to the size of the dog, four
times a day. After the acute stage is passed, then a good tonic is
desirable and for this purpose either Le Roy’s Condition Pills,
Sergeant’s or Glover’s are useful.
Another serious complication that frequently arrives is when it
attacks the lungs, and this is not at all uncommon; pneumonia being
one of the situations to guard against. Where there is a sudden rise
in temperature and the dog is inclined to sit on his haunches, bracing
himself on his forelegs, which are spread far apart, and his breathing
comes fast and sharp, it may be taken for granted that pneumonia is
the cause. By placing the ear to the chest one can hear the labored
breathing which sounds very much like someone walking over frozen
snow.
If the dog is not already wearing a chest jacket make one for him at
once. Sometimes strong liniments are effective. But one of the
simplest things to use is hot lard and turpentine. Grease the chest
well with this, wrap flannels around him and put the jacket over all.
Apply fresh turpentine and lard every two hours, until the breathing is
easier. The following is a very good formula to use internally:
Extract of Belladonna 1/2 grain
James’ Powder 4 grains
Nitrate of Potash 8 grains
Extract of Gentian, enough to make one pill
For medium-sized dogs make up twelve pills with the above
ingredients and give 1 three times daily. If the fever does not subside
readily it might be well to give them drops of aconite in a
tablespoonful of water, every three hours. Perpetual vigilance is
necessary in the successful combating of pneumonia and as in every
other phase of distemper, care and good nursing are most important.
For a more extended treatise on distemper, “Dogcraft,” third edition,
will be of great benefit to all dog owners.
Few dogs go through life without having Worms at some time in their
career and in the case of puppies, we doubt if any ever escape these
intestinal pests. Usually the kennel owner or dealer, worms the
puppies before he sells them, hence the future owner has little to
fear, although it must not be supposed that when a vermifuge is
given to a puppy once or even two or three times during his young
life, that he will be forever free from worms. On the other hand, he is
likely to have them at any time, though the danger of fatal results is
far less.
There are numerous remedies that may be used very effectively for
the various kinds of worms, such as areca nut, santonin, pink and
senna, kamala, etc., but I believe the safest plan for the novice is to
procure any one of the reliable proprietary remedies that are on the
market, for it will be less trouble to give these and there is little
danger of going wrong, which might be the case were the neophyte
to dabble with unknown drugs.
For Tape Worm—and many more dogs suffer from this than one
might suppose—kamala and areca nut in equal parts is very
effective. That is, for large dogs give two grains (one grain of each
drug) to the pound weight of the dog after fasting twenty-four to
thirty-six hours. One hour after giving the vermifuge the dog should
have a liberal dose of castor oil. The symptoms of tape worm are
varied. The dog may have a capricious appetite, his coat becomes
harsh and stary, he looks thin and emaciated and he has a habit of
rubbing his sides and back up along fences or buildings. His breath
is usually offensive and his eyes lack luster and frequently form pus
in the corners.
In the South the Hook Worm is the bane of all dog owners and it is
becoming more prevalent every year. Indeed, of late years it has
been invading the North also, which is probably due to field trials and
bench shows, as dogs from the North are taken South where they
become infested and thus bring the pests back to their homes.
Recently a very good specific for hook worms has been discovered
and from all accounts it is giving excellent results. The drug is carbon
tetrachloride. The dose is one drop for each pound weight of the dog
after fasting twenty-four hours. The drug should be placed in hard
capsules and administered in that manner. It is not necessary to
follow with a purgative as is the case with most other vermifuges.
This new remedy has been given to very young puppies with the
best results. It should always be remembered, however, that the
dosage should be one drop to the pound weight of the dog, no
matter how large or how small he is.
A dog affected with hook worms usually grows very thin, is dull and
apathetic, his coat is harsh and unnatural, his eyes lack fire and he
has little or no ambition, but the greatest tell-tale sign of all is his
gums and the mucous membrane of his eyes. Instead of being a
healthy pink, they become white and waxy. When the gums and
mouth are in this condition, then it is time to begin treatment for hook
worms.
One of the common disturbances that house dogs are subject to is
Fits. It is rather disheartening to the novice to see his dog roll over
suddenly and become stiff and rigid, for in most cases he is at a loss
what to do. Fits arise from various causes; through worms,
constitutional nervous disorders, the aftermath of distemper, but in
most cases with house dogs, because of constipation or indigestion.
If the trouble is due to the two latter causes, then they may be easily
overcome by a change of diet and more exercise, for there is where
the trouble generally lies. The dog is fed heartily, frequently of
indigestible food, he obtains little or no exercise and the inevitable
result is a disarrangement of bowels, stomach or liver. If the fits are
the aftermath of distemper, the dog may outgrow them, but if they
are constitutional, then little or nothing can be done. However, it is
fits of the first order—that is, due to derangement of the digestive
organs—which are the commonest among house dogs. The victim
may suddenly fall over, or he may remain on his feet, and if he does,
the toe nails will dig into the rug or carpet in a way that once seen
will always be recognized. These seizures are generally easily
overcome by applying warm applications to the abdomen, or hand
massage. The victim, however, should be given a purgative once a

You might also like