// Start is called before the first frame update void Start() { tileManager = GameObject.Find("TileManager").GetComponent <TileManager>(); var carSpawnGO = GameObject.Find("SpawnManager"); if (carSpawnGO != null) { carSpawnManager = carSpawnGO.GetComponent <CarSpawnManager>(); } //speed = speed / 4; Direction = spawnDir.East; if (rightTurnEvent == null) { rightTurnEvent = new UnityEvent(); } if (leftTurnEvent == null) { leftTurnEvent = new UnityEvent(); } if (backToNormalEvent == null) { backToNormalEvent = new UnityEvent(); } if (turnSucceed == null) { turnSucceed = new UnityEvent(); } player = GameObject.Find("Player"); }
public void getOffRamp() { if (turnSucceed != null) { turnSucceed.Invoke(); } if (backToNormalEvent != null) { backToNormalEvent.Invoke(); } Direction = nextDirection; moveDir = Direction; onRamp = false; spawnCars = true; isRotating = true; if (carSpawnManager != null) { carSpawnManager.rotateSpawn(rotatingClockwise, Direction); } //speed /= Mathf.Sqrt(2); }
// Update is called once per frame void Update() { if (tileAmnt < 5) { tileManager.SpawnTile(Direction); tilesUntilTurn--; //Debug.Log(tileAmnt); } if (tilesUntilTurn == 3 && clearTurn) { bool nextTurn = Random.value > 0.5f ? false : true; //Right or Left if (nextTurn) { // Right Turn if (Direction.Equals(spawnDir.North)) { nextDirection = spawnDir.East; } else { nextDirection = Direction + 1; } tileManager.SpawnTurnTile(Direction, false); rotatingClockwise = true; if (rightTurnEvent != null) { rightTurnEvent.Invoke(); } } else { // Left Turn if (Direction.Equals(spawnDir.East)) { nextDirection = spawnDir.North; } else { nextDirection = Direction - 1; } tileManager.SpawnTurnTile(Direction, true); rotatingClockwise = false; if (leftTurnEvent != null) { leftTurnEvent.Invoke(); } } //Debug.Log("NextDir: "+nextDirection); startTurnIndicator(nextTurn, Direction); clearTurn = false; Direction = nextDirection; } else if (tilesUntilTurn == 0) { clearTurn = true; tilesUntilTurn = 5; } if (isRotating) { isRotating = !isRotating; } if (speed > defaultSpeed * 2) { GameOverActive(); } }
void startTurnIndicator(bool turnLeft, spawnDir currDirection) { //Create arrow on UI //Boolean is for left or right turn, direction is the current travel direction }