private IEnumerator SpawnHumans() { float delay = startAfter <= 0.0f ? Random.Range(0.5f, 2.5f) : startAfter; yield return(new WaitForSeconds(delay)); while (true) { if (Random.Range(0, 100) < spawnChangePercentage && CountBeforeFirstTrafficLight(false) < maxWaitingTraffic) { GameObject humanObject = spawnObjects[Random.Range(0, spawnObjects.Length)]; HumanEngine human = humanObject.GetComponent <HumanEngine>(); human.path = path; human.firstId = firstId; human.firstTrafficLight = firstTrafficLight; human.secondId = secondId; human.secondTrafficLight = secondTrafficLight; human.pressurePlateEndNode = pressurePlateStartNode + 2; humanObject.transform.position = spawnPoint; humanObject.tag = "Human"; humanObject.transform.rotation = Quaternion.identity; humanObject.transform.Rotate(0.0f, spawnAngle, 0.0f); Instantiate(humanObject); } yield return(new WaitForSeconds(spawnTime)); } }
public int CountBeforeSecondTrafficLight() { int count = 0; foreach (GameObject car in GameObject.FindGameObjectsWithTag("Human")) { HumanEngine engine = car.GetComponent <HumanEngine>(); if (engine.secondId == secondId && engine.currentNode > pressurePlateStartNode + 2 && engine.currentNode <= pressurePlateStartNode + 4) { count++; } } return(count); }
public int CountBeforeFirstTrafficLight(bool usePressurePlateStart) { int count = 0; int ppsn = usePressurePlateStart ? pressurePlateStartNode : 0; foreach (GameObject car in GameObject.FindGameObjectsWithTag("Human")) { HumanEngine engine = car.GetComponent <HumanEngine>(); if (engine.firstId == firstId && engine.currentNode > ppsn && engine.currentNode <= pressurePlateStartNode + 2) { count++; } } return(count); }
private void Sensors() { RaycastHit hit; Vector3 sensorStartPosition = this.gameObject.transform.localPosition; sensorStartPosition += transform.forward * frontSensorDistance; sensorStartPosition.y += 1.0f; if (Physics.Raycast(sensorStartPosition, transform.forward, out hit, sensorLength)) { HumanEngine humanInFront = hit.collider.gameObject.GetComponentInParent <HumanEngine>(); if (humanInFront != null) { isBraking = true; Debug.DrawLine(sensorStartPosition, hit.point, Color.white); } } else { isBraking = false; } }