Multiple scripting help needed.

Hey guys,

I got a serious problem, I am new at Unity development, and I got 2 scripts to ask you guys.

First : I want to add a sound when I press Fire1.
Second : I want to make an animation faster and that is looping (Because a single shot G36C isn’t realistic)

Thank you for helping me guys,
Bye !

KeyPresses:

Sound:

Animation Speed:

For the first add a script, to look for a event, like Unity - Scripting API: Input.GetMouseButtonDown

I looked at this as well http://forum.unity3d.com/threads/102934-Play-a-sound-effect-with-code
So would think you can do something like

function Update()
{
if(Input.GetMouseButtonDown(0)) { PUTAUDIOCODEHERE }
}
That will trigger when the player presses Left Mouse button, you can change the ButtonDown to ButtonUp to trigger when they ‘click’ ie press and let go of the button then it triggers

To Play Sound

public class Test: MonoBehaviour
{
    
    public AudioClip Ac
    
   void Start()
   {
        //This is to Make the Animation faster
         this.animation["your Animatiion Name"].speed = 2;
   }    

    void Update()
    {
         if(Input.GetKey == KeyCode.F)
         {
	       //To Pay the Audio Clip , Audio Source Component need to be attached to the game object
               this.GetComponent<AudioSource>().PlayOneShot(Ac);
         }
   }
}

You do not need to do GetComponent here. Just use audio.PlayOneShot(ac); or if you have audio file attached to the AudioSource (and it is set not to loop) you can also do audio.Play()

Thank you for your help guys.
So I tried what you told me, but now what I get is this :

MissingMethodException: UnityEngine.AudioSource.play
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[ ] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[ ] args)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey15.<>m__9 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[ ] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[ ] args, System.Type scriptBaseType)
Shoot.Update () (at Assets/Scripts/Shoot.js:3)

Here is my script :

function Update () {
if (Input.GetKeyDown (KeyCode.Mouse0))
this.GetComponent(AudioSource);audio.play(“g36fire”);
animation.Play(“fire”);
}

The method is Play not play. Also - that GetComponent call does nothing.