//---------------------------------------------- // Realistic Car Controller // // Copyright © 2014 - 2023 BoneCracker Games // https://www.bonecrackergames.com // Buğra Özdoğanlar // //---------------------------------------------- using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// Used to slow down the vehicle by increasing drag. /// [AddComponentMenu("BoneCracker Games/Realistic Car Controller/Misc/RCC Speed Limiter")] public class RCC_SpeedLimiter : MonoBehaviour { private float defaultDrag = -1f; private void OnTriggerStay(Collider other) { RCC_CarControllerV3 carController = other.GetComponentInParent(); if (!carController) return; if (defaultDrag == -1) defaultDrag = carController.Rigid.drag; carController.Rigid.drag = .02f * carController.speed; } private void OnTriggerExit(Collider other) { RCC_CarControllerV3 carController = other.GetComponentInParent(); if (!carController) return; carController.Rigid.drag = defaultDrag; } }