﻿using UnityEngine;
using System.Collections;

public class GhostWhisper : MonoBehaviour {

	public AudioClip[] whispers;
	AudioSource audio;
	float r;

	// Use this for initialization
	void Start () {
		audio = GetComponent<AudioSource>();
		audio.clip = whispers[ Random.Range(0, whispers.Length)] ;
		audio.Play();
		r = Random.Range(0f, 1f);
		Debug.Log( r );
		StartCoroutine( EndMyLife(2.0f) );
	}
	
	// Update is called once per frame
	void Update () {
		
		if (r > 0.5f)  transform.Translate (Vector3.right * 10 * Time.deltaTime);
		else transform.Translate (Vector3.right * -10 * Time.deltaTime);
	}

	IEnumerator EndMyLife(float wait) {
		yield return new WaitForSeconds(wait);
		Destroy(gameObject);
	}
}
