IEnumerator FacingEngine(WaypointDataScript waypoint)
    {
        switch (waypoint.facing.facing)
        {
            case(FacingType.FREE_MOVEMENT):
                Debug.Log("Processing facing - FREE LOOK");
                StartCoroutine("FreeLook", waypoint.movement.moveTime);
                yield return new WaitForSeconds(waypoint.movement.moveTime);
                break;
            case(FacingType.LOOK_AND_RETURN):
            case(FacingType.LOOK_CHAIN):
                if (waypoint.facing.facing.Equals(FacingType.LOOK_AND_RETURN))
                    Debug.Log("Processing facing - LOOK AND RETURN");
                else
                    Debug.Log("Processing facing - LOOK CHAIN");
                StartFacing(waypoint);

                float waitTime = 0;
                for (int i = 0; i < waypoint.facing.lookPoints.Count; i++)
                {
                    waitTime += waypoint.facing.toFocusTimes[i];
                    waitTime += waypoint.facing.focusTimes[i];
                }
                waitTime += waypoint.facing.returnTime;
                yield return new WaitForSeconds(waitTime);
                break;
            case(FacingType.FORCED_LOCATION):
                Debug.Log("Processing facing - FORCED LOCATION");
                StartFacing(waypoint);
                yield return new WaitForSeconds(waypoint.movement.moveTime);
                break;
        }
        Debug.Log("Facing complete");
    }
    void AddFacing(WaypointDataScript point)
    {
        Vector3 focusPointPosition = point.position.transform.position + Vector3.forward + Vector3.right;

        point.facing.lookPoints.Add(InstantiateFocusPoint(focusPointPosition));
        point.facing.lookPoints[point.facing.lookPoints.Count - 1].transform.parent = point.position.transform;
        point.facing.toFocusTimes.Add(0);
        point.facing.focusTimes.Add(0);
    }
 IEnumerator FaceTargets(WaypointDataScript waypoint)
 {
     initialRotation = playerCam.transform.rotation;
     for (int i = 0; i < waypoint.facing.lookPoints.Count; i++)
     {
         Quaternion startRotation = playerCam.transform.rotation;
         Quaternion neededRotation = Quaternion.LookRotation((waypoint.facing.lookPoints[i].transform.position - playerCam.transform.position).normalized);
         for (float t = 0; t < 1; t += Time.deltaTime / waypoint.facing.toFocusTimes[i])
         {
             playerCam.transform.rotation = Quaternion.Lerp(startRotation, neededRotation, t);
             yield return null;
         }
         yield return new WaitForSeconds(waypoint.facing.focusTimes[i]);
     }
     StartCoroutine(ReturnToInitialFacing(waypoint));
 }
    WaypointDataScript CreateWaypoint(string pointName)
    {
        // Create new waypoint instance
        WaypointDataScript newWaypoint = new WaypointDataScript();

        /*Determine where to put new waypoint instance
         * First check if other waypoints exist.
         * If they do,
         *   place this waypoint relative to the last waypoint.
         * If they do NOT,
         *   find the player object.
         *   If the player object exists,
         *      place this waypoint relative to the player
         *   else
         *      place this waypoint at (0, 0, 0)
         *
         */
        if (engine.waypoints.Count > 0)
        {
            Vector3 finalPointPosition = engine.waypoints[engine.waypoints.Count - 1].position.transform.position;
            Vector3 offsetPosition = finalPointPosition + Vector3.forward + Vector3.right;
            newWaypoint.position = InstantiateWaypoint(offsetPosition);
        }
        else
        {
            if (GameObject.FindGameObjectWithTag("Player"))
            {
                newWaypoint.position = InstantiateWaypoint(player.transform.position);
            }
            else
            {
                newWaypoint.position = InstantiateWaypoint(Vector3.zero);
            }
        }

        newWaypoint.movement = new MovementsScript();
        newWaypoint.facing = new FacingsScript();
        newWaypoint.numEffects = 0;

        newWaypoint.movement.move = MovementType.WAIT;
        newWaypoint.movement.moveTime = 0;
        newWaypoint.facing.facing = FacingType.FREE_MOVEMENT;

        newWaypoint.position.gameObject.name = pointName;
        newWaypoint.position.transform.parent = waypointContainer.transform;

        return newWaypoint;
    }
 void CheckSingleLookPoint(WaypointDataScript point, string name)
 {
     // Check if there are any focus points
     // If not, create a focus point
     // If there are focus points, check if there is more than one
     // If so, delete all but one
     // If a focus point exists, check its name
     // Change the name if needed
     if (!GameObject.FindGameObjectWithTag("LookPoint"))
     {
         AddFacing(point);
     }
     else
     {
         if (GameObject.FindGameObjectsWithTag("LookPoint").Length > 1)
         {
             GameObject[] foundLookPoints = GameObject.FindGameObjectsWithTag("LookPoint");
             for (int i = 1; i < foundLookPoints.Length; i++)
             {
                 DestroyImmediate(foundLookPoints[i]);
             }
         }
         if (!GameObject.Find(name) && GameObject.FindGameObjectWithTag("LookPoint"))
         {
             GameObject lookPoint = GameObject.FindGameObjectWithTag("LookPoint");
             lookPoint.gameObject.name = name;
             lookPoint.gameObject.transform.parent = point.position.transform;
             point.facing.lookPoints.Add(lookPoint);
         }
     }
 }
 void StartFacing(WaypointDataScript waypoint)
 {
     StopCoroutine(ReturnToInitialFacing(waypoint));
     StartCoroutine(FaceTargets(waypoint));
 }
 IEnumerator ReturnToInitialFacing(WaypointDataScript waypoint)
 {
     for (float t = 0; t < 1; t += Time.deltaTime / waypoint.facing.returnTime)
     {
         playerCam.transform.rotation = Quaternion.Lerp(playerCam.transform.rotation, initialRotation, t);
         yield return null;
     }
 }