/* * Spawns a random enemy */ void SpawnEnemy(float roadZ) { //TODO: Generate random enemy // generates random side position float enemyX = 0; float enemyZ = 0; // chooses what enemy to spawn int enemyType = Random.Range(0, 3); GameObject vehicle = pfVehicles[0]; if (enemyType == 0) { vehicle = pfPoliceCar; } if (enemyType == 1) { vehicle = pfAmbulance; } if (enemyType == 2) { vehicle = pfVehicles[Random.Range(0, pfVehicles.Count)]; } // defines a direction (left or right) and sets the lane position Utils.VehicleDirection direction = (Utils.VehicleDirection)Random.Range(0, 2); switch (direction) { case Utils.VehicleDirection.Left: enemyX = settings.GameRightBoundary; enemyZ = roadZ + (2 * Constants.Dimension.PathSizeZ + 1) + Constants.Dimension.PathSizeZ / 2; break; case Utils.VehicleDirection.Right: enemyX = settings.GameLeftBoundary; enemyZ = roadZ + Constants.Dimension.PathSizeZ + Constants.Dimension.PathSizeZ / 2; break; } Vector3 enemyPosition = new Vector3(enemyX, 2, enemyZ); // instantiates enemy at position GameObject enemy = InstantiateSceneObject(vehicle, enemyPosition); VehicleController model = enemy.GetComponent <VehicleController>(); model.SetDirection(direction); model.Go(); }
/* * Sets the direction of this vehicle */ public void SetDirection(Utils.VehicleDirection d) { direction = d; // define target point if (d == Utils.VehicleDirection.Left) { target = new Vector3(settings.GameLeftBoundary - 50, transform.position.y, transform.position.z); } else if (d == Utils.VehicleDirection.Right) { transform.rotation *= Quaternion.Euler(0, 0, 180f); // must rotate 3d asset target = new Vector3(settings.GameRightBoundary + 50, transform.position.y, transform.position.z); } }
/* * Given a lane, returns the start position of the vehicle on the chosen lane */ LaneDirection GetVehicleStartPointOnLane(Lane lane) { Vector3 lanePosition = new Vector3(0, settings.vehicleSettings.vehicleDefaultY, 0); Utils.VehicleDirection direction = Utils.VehicleDirection.Left; switch (lane) { case Lane.NormalLeftDirection: lanePosition.x = settings.GameRightBoundary; lanePosition.z = transform.position.z + Constants.Dimension.LaneNormalLeftDirectionZ; direction = Utils.VehicleDirection.Left; break; case Lane.NormalRightDirection: lanePosition.x = settings.GameLeftBoundary; lanePosition.z = transform.position.z + Constants.Dimension.LaneNormalRightDirectionZ; direction = Utils.VehicleDirection.Right; break; case Lane.AvenueLeftDirectionL: lanePosition.x = settings.GameRightBoundary; lanePosition.z = transform.position.z + Constants.Dimension.LaneAvenueLeftDirectionLZ; direction = Utils.VehicleDirection.Left; break; case Lane.AvenueLeftDirectionR: lanePosition.x = settings.GameRightBoundary; lanePosition.z = transform.position.z + Constants.Dimension.LaneAvenueLeftDirectionRZ; direction = Utils.VehicleDirection.Left; break; case Lane.AvenueRightDirectionL: lanePosition.x = settings.GameLeftBoundary; lanePosition.z = transform.position.z + Constants.Dimension.LaneAvenueRightDirectionLZ; direction = Utils.VehicleDirection.Right; break; case Lane.AvenueRightDirectionR: lanePosition.x = settings.GameLeftBoundary; lanePosition.z = transform.position.z + Constants.Dimension.LaneAvenueRightDirectionRZ; direction = Utils.VehicleDirection.Right; break; } return(new LaneDirection(lanePosition, direction)); }
public LaneDirection(Vector3 pos, Utils.VehicleDirection dir) { direction = dir; startPosition = pos; }