Error when trying to play sound by pressing a key

Hi, I’m having trouble getting a sound to play when you press the Fire Button, I’m still new to scripting so I may order things in scripts wrong.

My error Message is this “Expressions in statements must only be executed for their side-effects.”

Here’s what I’ve got

var projectile : Rigidbody;
var speed = 20;

function Update()
{

  if( Input.GetButtonDown( "Fire1" ) )
  {                                                                  
    //My problem is here, have i done this wrong with the "MP5 Shot";
    
    audio.Play();
    "MP5 Shot";
    
    // Delay a clip by 1 sec (44100 samples)
    audio.Play(44100); 
    
    var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
    instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
    Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider );
  }

}

You may recognise it from the FPS Tutorial, What i’m doing is not following the tutorial, I’m modifing the FPS Controller to my needs and also experimenting too, so I become more familiar with scripting, The Unity Script Resource is what’s helping alot, researching what type of script I’ll need and then placing it into the script and modifying it.

Can anyone help me please? I’m using Javascript

you can’t have a string floating out in the middle of nowhere, it doesn’t relate to anything.

chances are you probably meant do do something like this:

audio.Play(“MP5 Shot”);

In order to play a sound, you need to:

1- Add an Audio Source to the object to which this script is attached.

2- Import the sound (if it has not been imported yet) to your project with Assets->Import New Asset… menu option.

3- Click the Audio Clip dot button at Audio Source and select the sound.

4- Play the sound in your script using audio.Play();

In your case, I suppose you will not want to play the sound 1 second after the projectile has been fired (it seems to make no sense at all), so you should use:

  ...
  if( Input.GetButtonDown( "Fire1" ) )
  {
     audio.Play();
     var instantiatedProjectile : Rigidbody = Instantiate(...