public void Awake() { if (instance == null) { instance = this; PopulatePaths(); } }
// Set spawn positions private void CreateSpawnPositions() { List <AI_Path> list = AI_Grid.GetPathList(); float width = Vector3.Distance(list[0].StartPosition, list[0].EndPosition); float marginXAxis = (width / (spawnPointsPerRow - 0.99f)) * spawnPointSpacing; float marginYAxis = Vector3.Distance(list[0].StartPosition, list[1].EndPosition); int rows = list.Count() - 1; spawnRows = Mathf.Clamp(spawnRows, 1, rows); rows = spawnRows; spawnPositions = new Vector3[rows * spawnPointsPerRow]; spawnPositionsTop = new Vector3[spawnPointsPerRow]; float xPosition = list[0].StartPosition.x; float yPosition = list[0].StartPosition.y; int directionToggle = 1; int counter = 0; // Set positions int loops = rows; for (var i = 0; i < loops; i++) { float yPos = yPosition - (marginYAxis * i); // Swap if (i % 2 == 0) { xPosition = list[0].StartPosition.x; directionToggle = 1; } else { xPosition = list[0].EndPosition.x; directionToggle = -1; } // Colums for (var j = 0; j < spawnPointsPerRow; j++) { float xPos = xPosition + (marginXAxis * j) * directionToggle; spawnPositions[counter] = new Vector3(xPos, yPos, list[0].StartPosition.z); // Top (exception) if (i < 1) { float xPosTop = xPosition + (width / (Mathf.Clamp(spawnPointsPerRow - 0.99f, 0.99f, 100))) * j; if (spawnPointsPerRow == 1) { xPosTop = xPosition + (width / 2); } float yPosTop = yPosition + marginYAxis; spawnPositionsTop[counter] = new Vector3(xPosTop, yPosTop, list[0].StartPosition.z); } counter++; } } }
void OnDrawGizmos() { if (Application.isPlaying == false) { if (instance == null) { instance = this; } PopulatePaths(); for (int i = 0; i < rows; i++) { AI_Path path = paths[i]; Gizmos.color = Color.green; Gizmos.DrawLine(path.StartPosition, path.EndPosition); } Gizmos.color = Color.blue; Gizmos.DrawLine(sniperPath.StartPosition, sniperPath.EndPosition); } }