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

public class Bullet : MonoBehaviour
{

    public float speed = 10; //velocidade do projétil    
    public float destroyTime = 1.5f; // Destroi o projétil após 1 segundo e meio
    public AudioSource tiro;


    // Use this for initialization
    void Start()
    {
        tiro = GetComponent<AudioSource>();
        Destroy(gameObject, destroyTime); //Função que destrói o objeto
        tiro.Play();
    }

    // Update is called once per frame
    void Update()
    {

        transform.Translate(Vector3.right * speed * Time.deltaTime); //Movimentação da bala, movimenta para direita, multiplica pela velocidade e por estar fazendo a movimentação pelo update precisa do recurso time.deltatime para a movimentação ser independente dos frames.

    }

    private void OnTriggerEnter2D(Collider2D other)
    {

        if (other.gameObject.tag == "Enemy")
        {
            Destroy(gameObject);
        }
        if (other.gameObject.tag == "Boss")
        {
            Destroy(gameObject);
        }
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Ground"))
        {
            Destroy(gameObject);
        }

    }
}