using UnityEngine;
using System.Collections;

[RequireComponent(typeof(TracerScore))]
public class TracerCollisionHandler : MonoBehaviour {

    public Object explosionPrefab;

    public void Awake() {
        if (explosionPrefab == null) {
            Debug.LogWarning("Explosion Prefab was not assigned,"
                            + " there will be no fancy explosions!", this);
        }
    }

    public void OnCollisionEnter() {
        GameStateManager.Instance.PlayerCrashed(); 
        if (explosionPrefab != null) {
            Instantiate(explosionPrefab,
                        transform.position,
                        transform.rotation);
        }
        gameObject.SetActive(false);
    }

    public void OnTriggerEnter(Collider other) {
        if (other.transform.parent != null) {
            Transform appleTransform = other.transform.parent;
            Apple apple = appleTransform.GetComponent<Apple>();
            if (apple != null) {
                TracerScore tracerScore = this.GetComponent<TracerScore>();
                tracerScore.AddScore(apple.Score);

                appleTransform.gameObject.SetActive(false);

                GameStateManager.Instance.AppleCollected();
            }
        }
    }

}