Hi,
I am using the UnityCar(s) for my Racing Game. I’m working on some twists, one of them being the Speed increase when going through a collider. As of now, the default speed of these cars is put to:
[SerializeField] public static float m_Topspeed = 20;
When a Car hits a collider (3D Cube as an example), the Car will gain speed set by the multiplier. Now, I can’t seem to find a solution to this on regulating how long this duration is and when this boost stops. I thought that OnTriggerExit would stop this speed increase but for some reason, the boost starts from that point on.
Here is my script, how would I fix this issue?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Vehicles.Car;
public class SpeedIncrease : MonoBehaviour
{
public float multiplier = 0.1f;
public GameObject DriveThroughEffect;
public AudioSource BoostSound;
public GameObject Car;
public GameObject AI01;
public GameObject AI02;
void OnTriggerEnter(Collider other)
{
Instantiate(DriveThroughEffect, transform.position, transform.rotation);
BoostSound.Play();
CarController.m_Topspeed *= multiplier;
Debug.Log("ReceiveBoost");
}
void OnTriggerExit(Collider other)
{
CarController.m_Topspeed /= multiplier;
}
}