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

public class AivoScript : MonoBehaviour {

    bool alive;
    float starttime;
    float lastshoot;

    public GameObject bullet;

	// Use this for initialization
	public void StartIt()
    {
        alive = true;
        starttime = Time.time;
        lastshoot = Time.time + 5;

        GetComponent<Animator>().SetBool("move", true);

    }

    void FixedUpdate()
    {
        if (!alive) return;
        if (Time.time > lastshoot + 4) {
            lastshoot = Time.time;
        }

        if (Time.time > lastshoot && Time.time < lastshoot + 1)
        {
            if (Random.Range(0,5) == 0)
            {
                Vector3 dir = GameObject.Find("player").transform.position - transform.position;
                GameObject bull = GameObject.Instantiate(bullet, transform.position, Quaternion.identity);
                bull.GetComponent<Rigidbody2D>().velocity = dir*1.5f;
                Destroy(bull, 0.9f);
            }
        }
    }
}
