} // getcell // Generate the corridor public void Generate() { cells = new CorridorCell[size.x, size.z]; bool turned = false, turnedRecently = false; // Current coordinates, initialised with -1, -1 IntVector2 currentCoordinates; // Coordinates to generate the next cell on IntVector2 nextCoordinates = RandomCoordinates; // The direction to generate the next cell to CorridorDirection nextDirection = CorridorDirections.RandomValue; // Direction of the current cell CorridorDirection currentDirection = nextDirection; CreateFirstCell(nextCoordinates, nextDirection); currentCoordinates = nextCoordinates; currentDirection = nextDirection; // Generate the cells while (true) { turned = false; // Check if change direction or not if (Random.Range(0, 100) < cornerProbability && !turnedRecently) { // Try random direction. If wrong, try until right nextDirection = CorridorDirections.RandomValue; while (nextDirection == CorridorDirections.OppositeOf(currentDirection)) { nextDirection = CorridorDirections.RandomValue; } // while turned = true; } // if else { nextDirection = currentDirection; } turnedRecently = turned; nextCoordinates += currentDirection.ToIntVector2(); if (!(ContainsCoordinates(nextCoordinates) && GetCell(nextCoordinates) == null)) { break; } CreateCell(nextCoordinates, currentDirection, nextDirection); cellList.Add(GetCell(currentCoordinates)); currentDirection = nextDirection; currentCoordinates = nextCoordinates; } // while // Spawn the npcs if (GameManager.instance.enemies) { corridorSpawnNPCs(); } } // generate