private IEnumerator DelayedBlinkersTurnOff() { yield return(new WaitForSeconds(blinkerSum)); if (blinkerMode != VehicleBlinkerMode.None) { blinkerMode = VehicleBlinkerMode.None; } }
internal static void LoopBlinker(VehicleBlinkerMode light, Action <Vector3> act) { try { switch (light) { case VehicleBlinkerMode.Left: act(blinkerPos[VehicleLight.FrontLeft]); act(blinkerPos[VehicleLight.RearLeft]); break; case VehicleBlinkerMode.Right: act(blinkerPos[VehicleLight.FrontRight]); act(blinkerPos[VehicleLight.RearRight]); break; } } catch { } }
private void Update() { float horAxis = Input.GetAxis("Horizontal"); // Set car lights if (HasDriver) { if (horAxis != 0) { blinkerMode = horAxis < 0 ? VehicleBlinkerMode.Left : VehicleBlinkerMode.Right; } else if (horAxis == 0 && Steering == 0 && blinkerMode != VehicleBlinkerMode.None) { StartCoroutine(DelayedBlinkersTurnOff()); } } foreach (var wheel in _wheels) { Vector3 position = Vector3.zero; WheelHit wheelHit; if (wheel.Collider.GetGroundHit(out wheelHit)) { position.y = (wheelHit.point.y - wheel.Collider.transform.position.y) + wheel.Collider.radius; } else { position.y -= wheel.Collider.suspensionDistance; } wheel.Child.transform.localPosition = position; // reset the yaw wheel.Child.localRotation = wheel.Roll; // calculate new roll wheel.Child.Rotate(wheel.IsLeftHand ? Vector3.left : Vector3.right, wheel.Collider.rpm / 60.0f * 360.0f * Time.deltaTime); wheel.Roll = wheel.Child.localRotation; // apply yaw wheel.Child.localRotation = Quaternion.AngleAxis(wheel.Collider.steerAngle, Vector3.up) * wheel.Roll; } if (HasDriver) { if (Input.GetKeyDown(KeyCode.F)) { if (Vector3.Dot(transform.up, Vector3.down) > 0) { transform.position += Vector3.up * 1.5f; transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, 0); } } if (Input.GetKeyDown(KeyCode.L)) { m_frontLeftLightPowered = !m_frontLeftLight; m_frontRightLightPowered = !m_frontRightLightPowered; SetLight(VehicleLight.FrontLeft, m_frontLeftLightPowered ? VehicleAPI.frontLightIntensity : 0); SetLight(VehicleLight.FrontRight, m_frontRightLightPowered ? VehicleAPI.frontLightIntensity : 0); } if (Braking > 0.125f) { SetLight(VehicleLight.Rear, 1f); } else { SetLight(VehicleLight.Rear, 0f); } } else { if (IsAnyLightPowered()) { SetLight(VehicleLight.All, 0f); } Braking = 1f; } if (_colorsChanged) { UpdateColors(); } }
private void Update() { float horAxis = Input.GetAxis("Horizontal"); // Set car lights if (HasDriver) { if (horAxis != 0) { blinkerMode = horAxis < 0 ? VehicleBlinkerMode.Left : VehicleBlinkerMode.Right; } else if (horAxis == 0 && Steering == 0) { blinkerMode = VehicleBlinkerMode.None; } if (!_isNightToggled && WorldController.IsNight) { IsNightToggled = true; } else if (_isNightToggled && !WorldController.IsNight) { IsNightToggled = false; } } foreach (var wheel in _wheels) { Vector3 position = Vector3.zero; WheelHit wheelHit; if (wheel.Collider.GetGroundHit(out wheelHit)) { position.y = (wheelHit.point.y - wheel.Collider.transform.position.y) + wheel.Collider.radius; } else { position.y -= wheel.Collider.suspensionDistance; } wheel.Child.transform.localPosition = position; // reset the yaw wheel.Child.localRotation = wheel.Roll; // calculate new roll wheel.Child.Rotate(wheel.IsLeftHand ? Vector3.left : Vector3.right, wheel.Collider.rpm / 60.0f * 360.0f * Time.deltaTime); wheel.Roll = wheel.Child.localRotation; // apply yaw wheel.Child.localRotation = Quaternion.AngleAxis(wheel.Collider.steerAngle, Vector3.up) * wheel.Roll; } if (HasDriver) { if (m_frontLeftLightPowered) { SetLight(VehicleLight.FrontLeft, 1f); } if (m_frontRightLightPowered) { SetLight(VehicleLight.FrontRight, 1f); } if (Input.GetKeyDown(KeyCode.L)) { m_frontLeftLightPowered = !m_frontLeftLight; m_frontRightLightPowered = !m_frontRightLightPowered; } if (Braking > 0.125f) { SetLight(VehicleLight.Rear, 1f); } else { SetLight(VehicleLight.Rear, 0f); } } else { if (IsAnyLightPowered()) { SetLight(VehicleLight.All, 0f); } Braking = 1f; } if (_colorsChanged) { UpdateColors(); } }