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

public class EnemyBullet : MonoBehaviour {

    private Rigidbody rb;
    public int damage;
    public float speed;
	// Use this for initialization
	void Start ()
    {
        Destroy(this.gameObject, 5);
        rb = this.GetComponent<Rigidbody>();	
	}
	
	// Update is called once per frame
	void Update () {
		
	}
    private void OnTriggerEnter(Collider other)
    {
        if(other.tag== "Player")
        {
            other.gameObject.GetComponent<PlayerHealth>().ModifyHealth(-damage);
            Destroy(this.gameObject);
        }
        if(other.tag=="Walls")
        {
            Destroy(this.gameObject, 0.5f);
        }
    }
    private void FixedUpdate()
    {
        
        rb.velocity = transform.TransformDirection(Vector3.right * speed);
    }
}
