Hello, I made 2 scripts for taking damage from my zombie…Zombie is moving and I can kill him but…Whenever he gets in my collider I get damage and there is when it stops…The thing I want to make is to countinously take damage when Zombie is in my collider…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyScript : MonoBehaviour
{
float damage = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void OnTriggerEnter(Collider other)
{
other.gameObject.GetComponent<HealthScript>().TakeDamage(damage);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthScript : MonoBehaviour
{
public float max_health = 100f;
public float cur_health = 0f;
public bool alive = true;
// Start is called before the first frame update
void Start()
{
alive = true;
cur_health = max_health;
}
void DoDamage()
{
TakeDamage(10f);
}
public void TakeDamage(float amount)
{
if (!alive)
{
return;
}
if (cur_health <= 0)
{
cur_health = 0;
alive = false;
gameObject.SetActive(false);
}
cur_health -= amount;
}
// Update is called once per frame
}