I have a simple script which changes a float variable in another script (via GetComponent) when an input is pressed. At the moment the variable changes instantly but I would like to be able to control the speed at which this float variable changes while the input is pressed. For eg. if I press the input for a short time the float starts to approach the value but only reaches it if the input is pressed for a long enough time. How can I do this? In the “if” statement if I change the “=” to a “-=” of “+=” it does change the float over time but I still can’t control how fast it changes.
using UnityEngine;
using System.Collections;
public class HydraulicSuspension : MonoBehaviour {
public float lowRider = 0.1f;
public CarDynamics carDynamics;
//Use this before intialization
void Awake(){
carDynamics = GetComponent <CarDynamics>();
}
// Update is called once per frame
void FixedUpdate () {
//Check if Hydraulics is pressed
if(Input.GetAxisRaw("Hydraulics") == 1) {
carDynamics.suspensionTravelFront = lowRider;
carDynamics.SetCarParams();
}
}
}