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

public class BulletBehavior : MonoBehaviour {

    public float direction;
    public int damage;
    private Rigidbody rb;

	// Use this for initialization
	void Start () {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update () {
        //transform.position = transform.position + new Vector3(Mathf.Cos(Mathf.Deg2Rad * direction), 0, Mathf.Sin(Mathf.Deg2Rad * direction));
        rb.velocity = new Vector3(Mathf.Cos(Mathf.Deg2Rad * direction), 0, Mathf.Sin(Mathf.Deg2Rad * direction)) * 2000 * Time.deltaTime;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "pickup")
        {
            Physics.IgnoreCollision(GetComponent<Collider>(), collision.gameObject.GetComponent<Collider>());
        }
        if (collision.gameObject.tag != "Player" && collision.gameObject.tag != "Bullet" && collision.gameObject.tag != "EnemyBullet" && collision.gameObject.tag != "pickup")
        {
            if (!(damage == 10 && collision.gameObject.tag == "Enemy"))
                Destroy(gameObject);
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "pickup")
        {
            Physics.IgnoreCollision(GetComponent<Collider>(), other.gameObject.GetComponent<Collider>());
        }
        if (other.gameObject.tag != "Player" && other.gameObject.tag != "Bullet" && other.gameObject.tag != "EnemyBullet" && other.gameObject.tag != "pickup")
        {
            if (!(damage == 10 && other.gameObject.tag == "Enemy"))
                Destroy(gameObject);
        }
    }
}
