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

public class Inst : MonoBehaviour
{
    public GameObject head,body,legs;
    public float tiempo,tiempomax,tiempomin,spawntiempo;    

    // Start is called before the first frame update
    void Start()
    {
        SetRandomTime();
        tiempo = tiempomin;        
    }

    // Update is called once per frame
    void FixedUpdate()
    {        
        tiempo += Time.deltaTime;        

        head.transform.position = transform.position;
        body.transform.position = transform.position;
        legs.transform.position = transform.position;


        
        if (tiempo > spawntiempo)
        {
            int Num = Random.Range(1, 4);
            if (Num == 1)
            {
                Instantiate(head);
                SetRandomTime();
                tiempo = 0;
            }
            if (Num == 2)
            {
                Instantiate(body);
                SetRandomTime();
                tiempo = 0;
            }
            if (Num == 3)
            {
                Instantiate(legs);
                SetRandomTime();
                tiempo = 0;
            }
        }
    }
    void SetRandomTime()
    {
        if (tiempo > spawntiempo)
        {
            spawntiempo = Random.Range(tiempomin, tiempomax);
            tiempo = 0;
        }        
    }
}
