Adjusting the FlightPoints Script

We have a few small changes to make to the FlightPoints script in order to tell it how to handle an enemy. Specifically, we need to tell it how and when to tell the enemy sprite to change its facing. The new code is introduced in Listing 9.12.

Listing 9.12 The Revised FlightPoints Script

public class FlightPoints : MonoBehaviour{  public GameObject waypointA;  public GameObject waypointB;  public float speed = 1;  public bool shouldChangeFacing = false;  private bool directionAB = true;  void FixedUpdate()  {    if(this.transform.position == waypointA.transform.position      && directionAB == false || this.transform.position ==      waypointB.transform.position && directionAB == ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.