using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TreeBehavior : MonoBehaviour {

    public float playerProximity = 6;
    public GameObject coconutPrefab;
    Transform player;
    public Transform coconutSpawner;

    int numberOfNuts = 3;

    // Start is called before the first frame update
    void Awake() {
        player = GameObject.FindGameObjectWithTag("Player").transform;
    }

    // Update is called once per frame
    void Update() {
        if (Vector3.Distance(player.position, transform.position) < playerProximity && numberOfNuts > 0) {
            if (Input.GetKeyDown(KeyCode.Space)) {
                GameObject coconut = Instantiate(coconutPrefab, coconutSpawner.position, Quaternion.identity);
                coconut.GetComponent<Item>().itemName = Item.ItemName.COCONUT;
                numberOfNuts--;
            }
        }
    }

    private void OnDrawGizmos() {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, playerProximity);
    }
}
