using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

public class Breakable : MonoBehaviour
{
    public AudioSource oldSource;
    public AudioSource newSource;
    public RunEventSequence sequence;
    public GameObject destroyedVase;
    public bool canBreak;

    public void SetCanBreak(bool enabled)
    {
        canBreak = enabled;
    }

    private void Update()
    {
        if (!canBreak)
            return;

        if (Input.GetMouseButtonDown(0))
        {
            Destroy(oldSource);
            newSource.Play();
            sequence.SetTimeRunning(true);

            FirstPersonController.freezeMovement = false;
            Quaternion rotationOnBrokenVase = Quaternion.Euler(90, 0, 0);
            Instantiate(destroyedVase, transform.position, transform.rotation * rotationOnBrokenVase);
            Destroy(gameObject);
        }
    }
}
