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

public class CorpseSpawner : MonoBehaviour 
{
    public static CorpseSpawner Instance;

    public float PartVelocityRandomFactor = 1.0f; 

    public GameObject[] parts;

    public void Awake()
    {

        Instance = this; 

    }

    public void SpawnCorpse(Vector2 position, Vector2 velocity, int pieces, float duration)
    {
        for(int n=0;n<pieces;n++)
        {
            Quaternion rotation = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), Vector3.forward); 
            GameObject objPart = GameObject.Instantiate(parts[Random.Range(0, parts.Length)], position, rotation);
            objPart.GetComponent<Rigidbody2D>().velocity = velocity + (new Vector2(Random.Range(-PartVelocityRandomFactor, PartVelocityRandomFactor), Random.Range(PartVelocityRandomFactor, PartVelocityRandomFactor))); 
            GameObject.Destroy(objPart, duration); 
        }
    }

}
