using UnityEngine;
using System.Collections;

public class ScareScript : MonoBehaviour {
	
	public int scare = 0;
	public float timer;
	AudioSource audsrc;

	// Use this for initialization
	void Start () {
		audsrc = GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {

		PlayerMoveScript playScript = GameObject.Find("Player").GetComponent<PlayerMoveScript>();
		
		if (Input.GetKeyDown (KeyCode.Space) && playScript.start == 1)
		{
			scare = 1;
			audsrc.Stop();
			audsrc.Play();
			GetComponent<SpriteRenderer> ().enabled = true;
		}

		if (scare == 1) {
			timer += Time.deltaTime;

			if (timer >= 0.12f)
			{
				scare = 0;
				GetComponent<SpriteRenderer>().enabled = false;
				timer = 0;
			}
		}
	}


}
