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

public class SpawnFood : MonoBehaviour
{
    // pick random position between min and max vector
    public Vector3 min = Vector3.zero;
    public Vector3 max = Vector3.one * 100f;

    public float foodEnergy = 10f;

    // Start is called before the first frame update
    void Start()
    {
        ReSpawn();
    }

    private void Update()
    {
        // in case it falls off the edge
        if (transform.position.y <= -10f)
            ReSpawn();
    }

    void ReSpawn()
    {
        var xPos = Random.Range(min.x, max.x);
        var yPos = Random.Range(min.y, max.y);
        var zPos = Random.Range(min.z, max.z);
        var pos = new Vector3(xPos, yPos, zPos);

        transform.position = pos;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.transform.CompareTag("npc"))
        {
            ReSpawn();
        }
    }
}
