Skip to content

Instantly share code, notes, and snippets.

@jquave
Created December 19, 2013 02:26
Show Gist options
  • Select an option

  • Save jquave/8033403 to your computer and use it in GitHub Desktop.

Select an option

Save jquave/8033403 to your computer and use it in GitHub Desktop.
public void SpawnVehicles() {
// Spawn between 3 and 6 vehicles
float carWidth = 10.0f;
for(int i=0;i<Random.Range(3,6);i++) {
Vector3 vPos = playerTransform.position;
vPos += (40.0f*i+40.0f)*Vector3.forward;
//float laneStartX = xStart;
float rx = Random.Range(xStart + carWidth, xStart+levelWidth - carWidth);
GameObject vehicle = (GameObject)Instantiate(vehiclePrefab, vPos, Quaternion.Euler(0,180,0));
Runner tRunner = vehicle.GetComponent<Runner>();
tRunner.gameLogic = this.gameLogic;
AIDriver aiDriver = tRunner.GetComponent<AIDriver>() as AIDriver;
Obstacle obstacle = aiDriver.GetComponent<Obstacle>() as Obstacle;
if(aiDriver)
nextSlice.AddObstacle(obstacle);
else
Debug.LogError("An AI driver was spawned with no AIDriver component. This shouldn't happen.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment