Mastering Unity Scripting
eBook - ePub

Mastering Unity Scripting

Alan Thorn

Share book
  1. 380 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Unity Scripting

Alan Thorn

Book details
Book preview
Table of contents
Citations

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Mastering Unity Scripting an online PDF/ePUB?
Yes, you can access Mastering Unity Scripting by Alan Thorn in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in C#. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781784390655

Mastering Unity Scripting


Table of Contents

Mastering Unity Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Unity C# Refresher
Why C#?
Creating script files
Instantiating scripts
Variables
Conditional statements
The if statement
The switch statement
Arrays
Loops
The foreach loop
The for loop
The while loop
Infinite loops
Functions
Events
Classes and object-oriented programming
Classes and inheritance
Classes and polymorphism
C# properties
Commenting
Variable visibility
The ? operator
SendMessage and BroadcastMessage
Summary
2. Debugging
Compilation errors and the console
Debugging with Debug.Log – custom messages
Overriding the ToString method
Visual debugging
Error logging
Editor debugging
Using the profiler
Debugging with MonoDevelop – getting started
Debugging with MonoDevelop – the Watch window
Debugging with MonoDevelop – continue and stepping
Debugging with MonoDevelop – call stack
Debugging with MonoDevelop – the Immediate window
Debugging with MonoDevelop – conditional breakpoints
Debugging with MonoDevelop – tracepoints
Summary
3. Singletons, Statics, GameObjects, and the World
The GameObject
Component interactions
GetComponent
Getting multiple components
Components and messages
GameObjects and the world
Finding GameObjects
Comparing objects
Getting the nearest object
Finding any object of a specified type
Clearing a path between GameObjects
Accessing object hierarchies
The world, time, and updates
Rule #1 – frames are precious
Rule #2 – motion must be relative to time
Immortal objects
Understanding singleton objects and statics
Summary
4. Event-driven Programming
Events
Event management
Starting event management with interfaces
Creating an EventManager
Code folding in MonoDevelop with #region and #endregion
Using EventManager
Alternative with delegates
MonoBehaviour events
Mouse and tap events
Application focus and pausing
Summary
5. Cameras, Rendering, and Scenes
Camera gizmos
Being seen
Detecting the object visibility
More on the object visibility
Frustum testing – renderers
Frustum testing – points
Frustum testing – occlusion
Camera vision – front and back
Orthographic cameras
Camera rendering and postprocessing
Camera shake
Cameras and animation
Follow cameras
Cameras and curves
Camera paths – iTween
Summary
6. Working with Mono
Lists and collections
The List class
The Dictionary class
The Stack class
IEnumerable and IEnumerator
Iterating through enemies with IEnumerator
Strings and regular expressions
Null, empty strings, and white space
String comparison
String formatting
String looping
Creating strings
Searching strings
Regular expressions
Infinite arguments
Language Integrated Query
Linq and regular expressions
Working with Text Data Assets
Text Assets – static loading
Text Assets – loading from the local files
Text Assets – loading from the INI files
Text Assets – loading from the CSV files
Text Assets – loading from the Web
Summary
7. Artificial Intelligence
Artificial Intelligence in games
Starting the project
Baking a navigation mesh
Starting an NPC agent
Finite State Machines in Mecanim
Finite State Machines in C# – getting started
Creating the Idle state
Creating the Patrol state
Creating the Chase state
Creating the Attack state
Creating the Seek-Health (or flee) state
Summary
8. Customizing the Unity Editor
Batch renaming
C# attributes and reflection
Color blending
Property exposing
Localization
Summary
9. Working with Textures, Models, and 2D
Skybox
Procedural meshes
Animating UVs – scrolling textures
Texture painting
Step 1 – creating a texture blending shader
Step 2 – creating a texture painting script
Step 3 – setting up texture painting
Summary
10. Source Control and Other Tips
Git – source control
Step #1 – downloading
Step #2 – building a Unity project
Step #3 – configuring Unity for source control
Step #4 – creating a Git repository
Step #5 – ignoring files
Step #6 – creating the first commit
Step #7 – changing files
Step #8 – getting files from the repo
Step #9 – browsing the repo
Resources folder and external files
AssetBundles and external files
Persistent data and saved games
Summary
Index

Mastering Unity Scripting

Copyright © 2015 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: January 2015
Production reference: 1230115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-065-5
www.packtpub.com

Credits

Author
Alan Thorn
Reviewers
Dylan Agis
John P. Doran
Alessandro Mochi
Ryan Watkins
Commissioning Editor
Dipika Gaonkar
Acquisition Editor
Subho Gupta
Content Development Editors
Melita Lobo
Rikshith Shetty
Technical Editors
Shashank Desai
Pankaj Kadam
Copy Editors
Karuna Narayanan
Laxmi Subramanian
Project Coordinator
Kinjal Bari
Proofreaders
Samuel Redman Birch
Ameesha Green
Indexer
Rekha Nair
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade

About the Author

Alan Thorn is a London-based game developer, freelance programmer, and author with over 13 years of industry experience. He founded Wax Lyrical Games in 2010, and is the creator of the award-winning game, Baron Wittard: Nemesis of Ragnarok. He is the author of 10 video-training courses and 11 books on game development, including Unity 4 Fundamentals: Get Started at Making Games with Unity, Focal Press, UDK Game Development, and Pro Unity Game Development with C#, Apress. He is also a visiting lecturer on the Game Design & Development Masters Program at the National Film and Television School.
Alan has worked as a freelancer on over 500 projects, including games, simulators, kiosks, serious games, and augmented reality software for game studios, museums, and theme parks worldwide. He is currently working on an upcoming adventure game, Mega Bad Code, for desktop computers and mobile devices. Alan enjoys graphics. He is fond of philosophy, yoga, and also likes to w...

Table of contents