engine sfx
This commit is contained in:
@@ -25,6 +25,9 @@ public class carController : MonoBehaviour
|
||||
public float carRotationSpeed;
|
||||
|
||||
public static bool isAlive = true;
|
||||
private AudioSource audioSource;
|
||||
public float maxVelocity = 100;
|
||||
public float EngineSFXsmooth = 0.05f;
|
||||
public static void GameOver(){
|
||||
if(!isAlive){return;}
|
||||
|
||||
@@ -81,6 +84,8 @@ public class carController : MonoBehaviour
|
||||
torqueF = torqueB = Torque[DataManager.SpeedLevel];
|
||||
|
||||
carRotationSpeed = RotationSpeed[DataManager.inAirLevel];
|
||||
|
||||
audioSource= GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -89,6 +94,7 @@ public class carController : MonoBehaviour
|
||||
if(!isAlive){
|
||||
rearWheel.useMotor = false;
|
||||
frontWheel.useMotor = false;
|
||||
audioSource.pitch = Mathf.Lerp(audioSource.pitch, 0,0.1f);
|
||||
return;
|
||||
}
|
||||
if (Input.GetAxisRaw("Horizontal") > 0)
|
||||
@@ -105,6 +111,8 @@ public class carController : MonoBehaviour
|
||||
motorBack.maxMotorTorque = torqueF;
|
||||
rearWheel.motor = motorBack;
|
||||
}
|
||||
|
||||
// RevEngine(2f);
|
||||
}
|
||||
else if (Input.GetAxisRaw("Horizontal") < 0)
|
||||
{
|
||||
@@ -120,13 +128,21 @@ public class carController : MonoBehaviour
|
||||
motorBack.maxMotorTorque = torqueB;
|
||||
rearWheel.motor = motorBack;
|
||||
}
|
||||
// RevEngine(1.5f);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rearWheel.useMotor = false;
|
||||
frontWheel.useMotor = false;
|
||||
// RevEngine(1);
|
||||
|
||||
}
|
||||
|
||||
// audioSource.pitch = 1 +(Mathf.Abs(GetComponent<Rigidbody2D>().velocity.magnitude) / maxVelocity);
|
||||
audioSource.pitch = Mathf.Lerp(audioSource.pitch, 1 +(Mathf.Abs(frontWheel.jointSpeed) / maxVelocity), EngineSFXsmooth);
|
||||
|
||||
|
||||
if (Input.GetAxisRaw("Horizontal") != 0)
|
||||
{
|
||||
GetComponent<Rigidbody2D>().AddTorque(carRotationSpeed * Input.GetAxisRaw("Horizontal") * 1);
|
||||
@@ -135,4 +151,9 @@ public class carController : MonoBehaviour
|
||||
|
||||
// CameraFollower.UpdateFrame();
|
||||
}
|
||||
|
||||
|
||||
// void RevEngine(float value){
|
||||
// audioSource.pitch = Mathf.Lerp(audioSource.pitch, value, revSfxSpeed);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user