using ScrambleKit.FX;
using UnityEngine;

public class CarSounds : MonoBehaviour 
{
    public AudioSource EngineSound;

    public float SoundPitchShiftRange = 0.1f;
    public float SoundBasePitch = 1.25f;

    private Rigidbody2D rb;

	void Start () 
	{
        rb = GetComponent<Rigidbody2D>();

	}

    void Update()
    {
        float speedFactor = Mathf.Min(1, rb.velocity.magnitude / 20f);
        EngineSound.pitch = SoundBasePitch + SoundPitchShiftRange * speedFactor;
    }

    public void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.name == "Goal")
            return;

        SoundFX.PlaySound("Clank");            
    }
}
