using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FighterHealth : MonoBehaviour
{
public int fighterhp = 100;
public int currenthp;
public GameObject pexplosion;
public int projectiledmg;
Collider2D col;
bool isDead;
bool damaged;
private void Start()
{
projectiledmg = GameObject.Find("Projectile").GetComponent<WeaponDMG>().projectiledmg;
}
void Awake()
{
currenthp = fighterhp;
col = GetComponent<Collider2D>();
}
void OnTriggerEnter2D(Collider2D projectile)
{
currenthp -= projectiledmg;
if (currenthp <= 0)
{
Death();
}
}
void Death()
{
isDead = true;
Destroy(gameObject);
Instantiate(pexplosion, transform.position, transform.rotation);
}
}
So this script is actualy working. But it does more then it should do. So i can shoot down enemy fighter the way i want to do. But if i ram the ship it acts the same way. so to say i can either shoot it 5 times or hit it 5 times with my spaceship. Why is it doing it? Any ideas what i must change to solve this?