using UnityEngine;
using System.Collections;

public class TrainCarDoorScript : MonoBehaviour {

	public AudioClip doorOpen1;
	public AudioClip doorOpen2;
	public AudioClip doorClose1;
	public AudioClip doorClose2;

	private float animationSpeed = 0.2f;
	private bool isDoorOpen = false;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
		//if(Input.GetKeyUp(KeyCode.Space)){
		//	interactWithDoor();
		//}

	}

	public void openDoor(){

		gameObject.animation["OpenDoor"].speed = animationSpeed;
		gameObject.animation.Play();
		isDoorOpen = true;

		if(Random.Range(0,2) == 1){
			audio.clip = doorOpen1;
		}else{
			audio.clip = doorOpen2;
		}
		audio.Play();

	}

	public void closeDoor(){

		gameObject.animation["OpenDoor"].speed = -animationSpeed;
		gameObject.animation["OpenDoor"].time = gameObject.animation["OpenDoor"].length;
		gameObject.animation.Play();

		isDoorOpen = false;

		if(Random.Range(0,2) == 1){
			audio.clip = doorClose1;
		}else{
			audio.clip = doorClose2;
		}
		audio.Play();
		
	}

	public void interactWithDoor(){

		if(!isDoorOpen){
			
			openDoor();
			//isDoorOpen = true;
			
		}else{
			
			closeDoor();
			//isDoorOpen = false;
			
		}

	}

	public bool isTrainCarDoorOpen(){
		return isDoorOpen;
	}


}
