Contents

1 Introduction
 1.1 Notes
 1.2 Computer Languages, Books and Teaching
  1.2.1 Computer languages
  1.2.2 Books and Teaching
 1.3 Pedagogy
 1.4 Legal-ish
2 First program and printing
 2.1 Hooking up a simple program
  2.1.1 Install/configure Unity3D
  2.1.2 Program set-up
  2.1.3 Errors in set-up
  2.1.4 A simple program
  2.1.5 Running it
 2.2 Statements, print
 2.3 Intro to computer math
 2.4 More writing program details
  2.4.1 White space
  2.4.2 Style
  2.4.3 Comments
 2.5 Errors, Syntax errors
  2.5.1 Compilers
  2.5.2 making some errors
 2.6 Adding more programs
 2.7 more math
3 Variables, computer math
  3.0.1 Literals
 3.1 Math with types
  3.1.1 mixed types
 3.2 Variables, declarations, simple assignment
 3.3 Identifiers
  3.3.1 Style
 3.4 Simple assignment, var use
  3.4.1 More assignment statement rules
  3.4.2 Initialization, unassigned vars
  3.4.3 Computer math with variables; types
  3.4.4 mixed-type assignments
 3.5 More assign and variable rules and examples:
  3.5.1 examples
 3.6 Declare/assign shortcuts
 3.7 Semi-useful variable and assign examples
 3.8 More error messages
  3.8.1 Run-time errors
 3.9 Doubles vs. floats
4 Input, more output, testing
 4.1 Input
 4.2 Using Update to make more interesting programs
 4.3 declare = shortcut and Inspector vars
 4.4 Replacing constants with variables
 4.5 Math shortcuts
 4.6 Fun 3D stuff
 4.7 more cute cube tricks
  4.7.1 Colors
  4.7.2 Scale
 4.8 Errors, funny stuff
5 Using a 3D environment
 5.1 Making a small room
  5.1.1 Intro
  5.1.2 A floor
  5.1.3 walls
 5.2 Color, Textures
 5.3 Adjusting the Camera
6 If statements
 6.1 Comparison Operators
 6.2 Some semi-useful ifs
 6.3 Compare precedence
 6.4 else
 6.5 And, Or
  6.5.1 Useful and/or’s
 6.6 Nested ifs
 6.7 Common errors
7 more if tricks
 7.1 falling through
  7.1.1 Cascading range-slicing ifs
  7.1.2 Do only one of these, none of the above
 7.2 Swapping
 7.3 Incremental calculations
  7.3.1 guessing game example
 7.4 Tricks with modulo
 7.5 Mixed and/or
  7.5.1 not, DeMorgan’s law
 7.6 Switch Statements
8 Unity if examples
 8.1 bouncing
  8.1.1 Speed increase
 8.2 Counting
 8.3 Delay counter
 8.4 State variables
9 Scope and Namespaces
 9.1 Scope
  9.1.1 Misc
  9.1.2 block scope
  9.1.3 Common errors
 9.2 Namespaces
  9.2.1 Notes/rules
10 More ifs and randomness
 10.1 Random rolls
 10.2 Random Positions
  10.2.1 Random size
  10.2.2 Color
 10.3 More things to randomize
 10.4 Coin flips, percents, random tables
11 Functions, part I
 11.1 Intro Function examples
 11.2 Function rules
 11.3 More function examples
  11.3.1 Longer resetToLeft example
 11.4 functions with more math
 11.5 Common Errors
 11.6 Style
 11.7 Chains of functions
  11.7.1 Multiple local scopes
12 Functions, part II - parameters
 12.1 Parameters
 12.2 Rules
 12.3 More rule-showing examples
 12.4 Fun errors
 12.5 Multiple Inputs
  12.5.1 More errors
13 Casting
 13.1 casting
  13.1.1 (int) from float
  13.1.2 (float) from int
  13.1.3 string casts, conversions
 13.2 char type
  13.2.1 char examples
  13.2.2 Casting chars
14 Functions, part III - return
 14.1 Introduction
 14.2 return values
 14.3 Using value-returning functions
 14.4 More math functions
  14.4.1 Extra return rules
  14.4.2 Optional empty return
  14.4.3 return can use math
  14.4.4 Errors
15 Constants and enums
 15.1 Constants
 15.2 enumerated types
  15.2.1 value returning ?: ifs
 15.3 More enumerated types
16 Overloading and default parms
 16.1 Introduction
 16.2 Default parameters
  16.2.1 overloading
 16.3 Style
17 booleans
 17.1 Boolean variables
 17.2 Bool rules
  17.2.1 bool variables in if statements
 17.3 Common bool tricks
  17.3.1 Pre-computing if tests
  17.3.2 bool return values
  17.3.3 Bools for function settings
  17.3.4 flags
  17.3.5 Incremental bool calculations
 17.4 Testing tricks
18 Function examples
 18.1 Introduction
 18.2 Change me type functions
 18.3 Dice functions
 18.4 More style; types of functions
 18.5 Moving curve examples
 18.6 Reading keys
 18.7 Making a real function library
 18.8 Unity built-ins
19 Structs
 19.1 Cow struct example
  19.1.1 More examples
 19.2 Common errors
 19.3 rules
  19.3.1 namespace vs. struct dots
 19.4 Builtin structs: Color, Vector3
  19.4.1 Color
 19.5 Constructors, struct literals
 19.6 Nested structs
 19.7 Structs as function inputs
 19.8 Structs as return values
 19.9 Uninitialized structs
20 Struct examples
 20.1 More Vector3, Color code
 20.2 More built-in functions
  20.2.1 Distance
  20.2.2 MoveTowards
  20.2.3 Color namespace
 20.3 Transform struct
  20.3.1 Special errors; pull-out trick
 20.4 Rigidbodies
  20.4.1 Simple physics set-up
  20.4.2 Playing with velocity
  20.4.3 Collision callback
  20.4.4 The Collision struct
  20.4.5 Misc event notes
21 Float problems
 21.1 The Problem
 21.2 Solutions
 21.3 < vs <= in float compares
22 Loops
 22.1 Special infinite loop warning
 22.2 Number-sequence loops
 22.3 While loop rules
 22.4 Do it 10 times loops
 22.5 Loops with floats
 22.6 Go until done loops
 22.7 More oddball loops
 22.8 Infinite/broken loops
 22.9 Move and count loops
 22.10 Digit tricks
 22.11 Fencepost errors
 22.12 for loops
 22.13 Count plus formula loops
 22.14 do-while loop
23 Index Loops
 23.1 Indexes
  23.1.1 Length of a string
 23.2 Variables as indexes
 23.3 String Loop examples
  23.3.1 Index inputs/outputs
 23.4 Odd string loops
24 Pointers
 24.1 First walk-through
 24.2 Terms and Theory
  24.2.1 Pointers
  24.2.2 new vs. Declare
  24.2.3 Reference type
 24.3 Common pointer/class use
 24.4 Functions and pointers
  24.4.1 Pointer inputs
  24.4.2 Pointer outputs
  24.4.3 Turn-input-into-output bug
 24.5 null
 24.6 Errors
 24.7 Fake new’s
 24.8 Pointer compare (==)
 24.9 Old-style pointers
25 Pointers in Unity
 25.1 Using pointers in Unity
  25.1.1 Pointers to existing Cubes
 25.2 Instantiate
  25.2.1 Instantiate as a copy
  25.2.2 Proper Unity use of Instantiate
  25.2.3 Variable GameObject pointers
  25.2.4 Pointers for “caching”
 25.3 New’ing Inspector variables
26 Pointer examples
 26.1 Text change
 26.2 More time, and APIs
 26.3 Three platforms
 26.4 More prefab use
 26.5 Multiple scripts
27 Using indexed lists
 27.1 Intro
 27.2 Creating Lists
 27.3 More playing with indexes
 27.4 List loop examples
  27.4.1 Initializing loops
  27.4.2 Printing
  27.4.3 List Searching
 27.5 Random item
  27.5.1 A list as a sequence
  27.5.2 Variable variables
  27.5.3 Moving parts of a list
 27.6 Two list tricks
 27.7 Size 0 and 1 lists
 27.8 Functions with lists
  27.8.1 Lists as inputs
  27.8.2 Returning lists
 27.9 errors
 27.10 Assign shortcut
28 Nested loops
 28.1 As a grid
 28.2 Pattern in pattern
 28.3 Wedge exercises
 28.4 break, continue
 28.5 List nested loops
  28.5.1 Sorting
29 Struct in struct
 29.1 Lists of structs
 29.2 Structs with Lists in them
 29.3 Lists of strings tricks
 29.4 2D lists
 29.5 Larger structures
 29.6 Giant game board example
 29.7 List of indexes
 29.8 Internal list pointers
30 Member functions
 30.1 Example and motivation
 30.2 More simple examples
 30.3 Using your own member functions
 30.4 Built-in member functions
  30.4.1 Unity member functions
  30.4.2 String member functions
  30.4.3 List member functions
 30.5 this
 30.6 Constructors
 30.7 Scope
 30.8 Style: member vs. non-member
31 Access modifiers
 31.1 How private variables work
 31.2 Classes as new types
 31.3 Interface/Implementation idea
  31.3.1 Rewriting classes
  31.3.2 Accessors
  31.3.3 get/set
32 Scripts as Classes
 32.1 How scripts really work
 32.2 Pointers to classes in Unity
  32.2.1 Multi-script ball-dropping game
  32.2.2 Hand-running fake updates
33 Nested classes, static
 33.1 Nested enum’s, classes and public
 33.2 Static / namespaces
  33.2.1 static functions
  33.2.2 Fake classes for namespaces
  33.2.3 static variables
  33.2.4 Fake global class
  33.2.5 File of classes
  33.2.6 Fun with scope
34 Reference parms
 34.1 ref rules
  34.1.1 ref vs. normal notes
 34.2 Output parameters
  34.2.1 out shortcut
 34.3 mixing real return and ref parms
 34.4 Pointers and References
 34.5 Raycast example
 34.6 Reference vs. reference?
35 Arrays
 35.1 Array rules
 35.2 shortcuts
 35.3 Arrays and functions
  35.3.1 Array work-arounds
 35.4 Max size / real size tricks
 35.5 List / array conversion
 35.6 OverlapSphere Unity example
 35.7 2D arrays
  35.7.1 Ragged [][] arrays
  35.7.2 Real 2D [,] arrays
36 Efficiency
 36.1 Most speed-ups don’t work
 36.2 Premature Optimization
 36.3 Not all code sections are equal
 36.4 Is it already fast enough?
 36.5 Will it cause more errors?
 36.6 Things that work
37 Debugging
 37.1 Test as you go
 37.2 How/what to test
 37.3 Tracking down bugs