Vector3 getPosForCreatingPoliceCar() { if (r == null) { r = FindObjectOfType <NewRoad> (); } NewRoadJunction rj = r.sectionsInTheRoad[Random.Range(0, r.sectionsInTheRoad.Count)]; Vector3 start = rj.startPoint.position; Vector3 end = rj.potentialPoints[Random.Range(0, rj.potentialPoints.Count)].transform.position; Vector3 dir = end - start; return(start + (Random.Range(0.0f, 1.0f) * dir.normalized)); bool junctionUnavailable = false; //if (copCarsAvailable.Count > 0) { foreach (GameObject g in copCarsInWorld) { if (Vector2.Distance(rj.startPoint.position, g.transform.position) < 4 && Vector2.Distance(rj.startPoint.transform.position, CommonObjectsStore.player.transform.position) < 12) { junctionUnavailable = true; //int r2 = Random.Range (0, copCarsAvailable.Count); //Vector3 p = copCarsAvailable [r2].transform.position; //copCarsAvailable.RemoveAt (r2); //return p; } } //} if (junctionUnavailable == false) { return(rj.startPoint.position); } else { return(getPosForCreatingPoliceCar()); } return(rj.startPoint.position); //List<NewRoadJunction> candidates = new List<NewRoadJunction> (); //foreach (NewRoadJunction rj in r.sectionsInTheRoad) { //if(rj.playerCarSpawn==true) // { //} }
public NewRoadJunction getNearestRoad(Vector3 pos) { float dist = 999999.0f; NewRoadJunction retVal = null; foreach (NewRoadJunction nj in sectionsInTheRoad) { float d = Vector3.Distance(nj.startPoint.position, pos); if (d < dist) { dist = d; retVal = nj; } } return(retVal); }
// Use this for initialization void Start() { if (hasDriver == false) { foreach (Light l in headlights) { l.enabled = false; } foreach (Light l in brakelights) { l.enabled = false; } } r = FindObjectOfType <NewRoad> (); rid = this.GetComponent <Rigidbody2D> (); nr = r.getNearestRoad(this.transform.position); nextJunct = nr.potentialPoints [Random.Range(0, nr.potentialPoints.Count)]; }
void atPosition() { nr = nextJunct; nextJunct = nr.potentialPoints [Random.Range(0, nr.potentialPoints.Count)]; }