
	private var footAudioSource : AudioSource;
	public var FPCSounds : AudioClip[];

	private var cc : CharacterController;
	private var cm : CharacterMotor;
	
	private var PlayTime : float = 0;
	private var JumpPlayed : boolean = false; 
	
	function Start(){
		var MyFPC : GameObject = GameObject.Find("First Person Controller");
		cc = MyFPC.GetComponent(CharacterController);
		cm = MyFPC.GetComponent(CharacterMotor);
		footAudioSource = this.GetComponent(typeof(AudioSource)) as AudioSource;
	}
	
	
	function Update(){
		if(Time.time < 0.5) return;
		
		//Parar los sonidos si no se mueve el FPC
		if(cc.velocity.magnitude == 0){
			if(footAudioSource.isPlaying){
				footAudioSource.Stop();
			}
			JumpPlayed = false;
			return;
		}
		
		// Si esta en el aire, reproducir el salto una sola vez.
		if(!cm.grounded){
			if(!JumpPlayed){
				//footAudioSource.Stop();
				footAudioSource.PlayOneShot(FPCSounds[1]);
				JumpPlayed = true;
			}
		}
		else{ // Reproducir los pasos.
			if(Time.time > PlayTime){
				if(cc.velocity.magnitude > 0 && cm.grounded){
					if(!footAudioSource.isPlaying){
						footAudioSource.Stop();
						footAudioSource.PlayOneShot(FPCSounds[0]);
						if(cc.velocity.magnitude <= 6)
							PlayTime += FPCSounds[0].length - 0.1;
						else
							PlayTime += (FPCSounds[0].length-0.1)/2;
							
						if(JumpPlayed)
							JumpPlayed = false;
					}
				}
			}
		}
	}
	
	