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() {
        Debug.Log("Collision detected - Tracer explodes!");
        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);
            }
        }
    }

}