other kind of damage except collision is not working please take not I “cannot” use “Is trigger” kind of damage because it affects the physics of the game like a car crash and air crash. I will modify the damage based on magnitude after the script works
using UnityEngine;
using UnityEngine.UI;
public class Enemy : MonoBehaviour
{
public float startHealth = 200;
private float health;
public float EnemyDistance;
public GameObject playerObj ;
public GameObject enemyObj;
[Header("Unity Stuff")]
public Image healthBar;
public float collisiondamage = 50;
private bool isDead = false;
void Start()
{
playerObj = GameObject.FindGameObjectWithTag(“Player”);
enemyObj = GameObject.FindGameObjectWithTag(“Enemy”);
health = startHealth;
}
public void LateUpdate()
{
EnemyDistance = Vector3.Distance(playerObj.transform.position, enemyObj.transform.position);
health = startHealth;
if (health <= 0 && !isDead)
{
Die();
}
}
public void Takedamagesix()
{
if (EnemyDistance <= 1.35)
{ health -= collisiondamage; }
}
void Die()
{
isDead = true;
Destroy(gameObject);
}
}