Errata: September 4, 2020

Thank you for purchasing Unity in Action, Second Edition. Please post any errors, other than those listed below, in the book's Author Online Forum. We'll update this list as necessary. Thank you!

Page 66

Beginning with code listing 3.10: Any time the SerializeField attribute appears in code listings, Unity will emit a warning if that field is not initialized in code. The script still functions fine so technically you could just ignore those warnings, but it's a simple tweak to make them go away. Any time you see a line like:

 [SerializeField] private GameObject enemyPrefab; 

change it to

 [SerializeField] private GameObject enemyPrefab = null;
Instruction in section 4.5.2 (page 92)
These instructions for applying a texture work in older versions of Unity, but imported materials work slightly differently now. There are several ways to make it work correctly, but the simplest is to first click Extract Materials in the Materials tab of the imported model.

Page 123

The tip recommends using TextMesh Pro but neglects to mention how. Add a final line:

Either get it free from Unity's Asset Store, or install it via Window > Package Manager.

Speed in listing 6.1 (page 132)
Unlike in previous chapters, we're manipulating the player's velocity not position, so delta time is not needed. Replace the first line in Update() with "float deltaX = Input.GetAxis("Horizontal") * speed;". Now the speed value needs to be much lower, so change the variable declaration to the following:
"public float speed = 4.5f;"

Number comparison in listing 6.5 (page 140)
The check "deltaX == 0" should be replaced with "Mathf.Approximately(deltaX, 0)". Thus the entire line of code becomes:
_body.gravityScale = (grounded && Mathf.Approximately(deltaX, 0)) ? 0 : 1;

Number comparison in listing 6.8 (page 143)
Similar to the previous change, the line "if (deltaX != 0)" should be replaced with "if (!Mathf.Approximately(deltaX, 0))". The latter appears in listing 6.2 and 6.8 refers to that same line of code, but 6.8 has the incorrect version.

Dot product in listing 9.3 (page 201)
When using the dot product to check facing, the vectors must be normalized (i.e. scaled to a length of 1 while retaining direction). Replace the dot product line with the following:
"if (Vector3.Dot(transform.forward, direction.normalized) > .5f) {"