private IEnumerator UpdatePathOnDelay(float delay) { while (true) { Vector3 next = GetNextIntersection(); Vector3 prev = GetPreviousIntersection(); // Stats now only shows the water level. //stats.GetComponentInChildren<Slider>().value = (Vector3.Distance(player.position, prev) + (fullPathLength - path.Count) * blockDist) / (blockDist * fullPathLength); //stats.GetComponentInChildren<Text>().text = playerCar.health.ToString(); if (next != Vector3.zero) { if (!pathingGraph.ContainsEdge(next, prev) && (player.position - next).sqrMagnitude > (player.position - prev).sqrMagnitude) { directionArrow.sprite = turnAroundArrow; directionArrow.gameObject.SetActive(true); fsm.DirectionAudio(3); } else if (!referenceGraph.ContainsEdge(next, prev) && (player.position - next).sqrMagnitude > (player.position - prev).sqrMagnitude) { //edge exists in pathing graph, but not in reference graph. Queue interaction to block edge in pathing graph pathingGraph.RemoveEdge(next, prev); bool onX = Mathf.Abs((next - prev).x) > 0f; int randSide = (int)Mathf.Sign(Random.Range(-1f, 1f)); GameObject toInstantiate = dynamicRoadBlockPrefabs[Random.Range(0, dynamicRoadBlockPrefabs.Count)]; int index = dynamicRoadBlockPrefabs.IndexOf(toInstantiate); Vector3 midpoint = (next + prev) / 2; Quaternion rot = Quaternion.Euler(0f, onX ? 90f : 0f, 0f); Instantiate(toInstantiate, midpoint, rot); fsm.ObstacleSound(index); } else { AStar(pathingGraph, next, endObj.position, out path); if (path.Count >= 2) { Vector3 nextDir = (path[1] - path[0]).normalized; TurnDirection(next, nextDir); } else { directionArrow.gameObject.SetActive(false); } } } else { directionArrow.gameObject.SetActive(false); } yield return(new WaitForSeconds(delay)); } }