// Use this for initialization void Start() { m_phases = new IntersectionPhase[3]; m_phases[0] = new IntersectionPhase(10f, 3f, 0, 1, lightToPhase_0); m_phases[1] = new IntersectionPhase(10f, 3f, 1, 2, lightToPhase_1); m_phases[2] = new IntersectionPhase(10f, 3f, 2, 0, lightToPhase_2); m_phases[m_currentPhase].SetPhaseState(PhaseState.ACTIVE); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Intersection")) { m_intController = other.GetComponent <IntersectionController>(); m_phase = m_intController.GetPhase(transform.forward); m_inIntersection = true; } }
private void Update() { if (m_following) { m_currentSpeed = m_carController.GetCurrentSpeed(); } else if (m_inIntersection && !runRed) { if (!m_slowingDown) { float stop_dist = Mathf.Abs(transform.position.z - m_intController.stop_z); float actual_stop_dist = (m_currentSpeed * m_currentSpeed) / (2f * deceleration); if (stop_dist <= actual_stop_dist) { m_slowingDown = true; } } else { m_currentSpeed -= deceleration * Time.deltaTime; if (m_currentSpeed < 0f) { m_currentSpeed = 0f; } } if (m_phase.CurrentState == PhaseState.ACTIVE) { m_slowingDown = false; m_inIntersection = false; m_phase = null; m_intController = null; } } else { m_currentSpeed += acceleration * Time.deltaTime; if (m_currentSpeed > max_speed) { m_currentSpeed = max_speed; } } if (m_inIntersection) { m_intController.CheckCar(this); } }