using UnityEngine;
public class Bullet : MonoBehaviour
{
[SerializeField] private float _Speed;
[SerializeField] private float _LifeTime;
[SerializeField] private float _Damage;
public float Damage
{
get { return _Damage; }
set { _Damage = value; }
}
private void Start()
{
Invoke(nameof(DestroyBullet), _LifeTime);
}
void Update()
{
transform.Translate(_Speed * Time.deltaTime * Vector2.up);
}
private void OnCollisionEnter2D(Collision2D collision)
{
var collisionIsEnemy = collision.gameObject.GetComponentInChildren<Enemy>();
if (collisionIsEnemy != null)
{
collisionIsEnemy.TakeDamage(_Damage);
DestroyBullet();
}
}
private void DestroyBullet()
{
Destroy(gameObject);
}
public void IncreaseDamage(float upgradeValue)
{
_Damage += upgradeValue;
}
}