using UnityEngine;

public class Spawner : MonoBehaviour
{
    public GameObject ItemToSpawn;
    
    private Vector3 m_boxCenter;
    private Vector3 m_boxSize;

    // Start is called before the first frame update
    void Start()
    {
        BoxCollider boxCollider = GetComponent<BoxCollider>();
        m_boxCenter = boxCollider.center;
        m_boxSize = boxCollider.size;
        
        Instantiate(ItemToSpawn, GetRandomPosition(), Quaternion.identity);
    }

    // Update is called once per frame
    //void Update()
    //{
        // DEBUG
    //    if (Input.GetKeyDown((KeyCode.U)))
    //    {
    //        Instantiate(ItemToSpawn, GetRandomPosition(), Quaternion.identity);
    //    }
    //}

    private Vector3 GetRandomPosition()
    {
        Vector3 randomPoint = new Vector3(Random.Range(-m_boxSize.x / 2, m_boxSize.x / 2), 
                                          Random.Range(-m_boxSize.y / 2, m_boxSize.y / 2),
                                          Random.Range(-m_boxSize.z / 2, m_boxSize.z / 2));
 
        return m_boxCenter + randomPoint;
    }
}
