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

public class NutSpawner : MonoBehaviour {
    public GameObject nut1;
    public GameObject nut2;

    public Transform spawnTarget;
    public int nuts;

	public void SpawnDemNuts()
    {
        for (int i = 0; i < nuts; i++)
        {
            GameObject nut = Random.Range(0, 2) == 0 ? nut1 : nut2;
            GameObject nnut = Instantiate<GameObject>(nut, spawnTarget.position, Quaternion.identity);

            Vector2 dir = new Vector2(transform.localScale.x, Random.Range(-0.5f, 0.5f));

            nnut.GetComponent<Rigidbody2D>().AddForce(dir.normalized * Random.Range(300, 600));

            Destroy(nnut, 5f);
        }
    }

    private void Update()
    {
        if (FakeInput.GetKeyUp(KeyCode.N))
        {
            SpawnDemNuts();
        }
    }
}
