Audio Script

Hi
I did this script with these intentions:

If I press A: Motore 1 increases (until its max-limit (2.0), and never stop, only if i press the key D or S). if motore 2 is running, decrease it and then stops.

If I press D:
Motore 2 increases (until its max-limit (2.0), and never stop, only if i press the key A or S). if motore 1 is running, decrease it and then stops.

If I press S: Motore 1 and Motore 2 decreasing an then stops. (minSpeed 0.2)

The soundpitch limits ranging from 0.2 to 2.0 (but this is already correct in my script)

But it’s wrong… someone can help me?

using UnityEngine;
using System.Collections;
 
public class Audio : MonoBehaviour
{
    public AudioClip Motore1;
    public AudioClip Motore2;
    float soundPitch = 0;
    float maxSpeed = 2;
    float minSpeed = 0.2f;
 
 
    void Start()
    {
       if (!audio.playOnAwake) audio.Play();
       Motore1_Vol = Motore1;
       Motore2_Vol = Motore2;
    }
 
 
    // Update is called once per frame
    void Update () 
    {
       soundPitch = Mathf.Clamp(soundPitch, minSpeed, maxSpeed);
 
 
       if (Input.GetKey(KeyCode.A)) 
       {
         audio.clip = Motore1;
         soundPitch+= 0.09f;
         audio.pitch = (soundPitch);
         Motore2_Vol = 0.0f;
         audio.volume = Motore1_Vol;
       }
 
 
 
       if (Input.GetKey (KeyCode.D)) 
       {
         audio.clip = Motore2;
         soundPitch+= 0.09f;
         audio.pitch = (soundPitch);
         Motore1_Vol = 0.0f;
         audio.volume = Motore2_Vol;
       }
 
 
       if (Input.GetKey (KeyCode.S)) 
       {
         soundPitch-= 0.09f;
         audio.pitch = (soundPitch);
       }
 
    }
 
 
}

If you want to play and mange multiple audio clips at once, you’ll need to create a new GameObject/AudioSource for each instance and keep track of them in your class. Once you do that, it’ll be easy to individually adjust the volumes.