hi there, I have an issue with my damage system for enemy. i want it so the enemies health decreases as the weapon is touching it. So far what happens is that it will do damage once on impact but no more. the only way to do more damage is to move sword away and re-hit the enemy. I want it so that when the sword is on the enemy, it does damage continously, not once.
Heres the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sworddamage : MonoBehaviour
{
public double damage;
public double delaytime = 1.4;
public GameObject Enemy;
public Animator animator;
public bool damageable;
void Update()
{
//StartCoroutine(takeDamage());
if (Input.GetButtonDown("Fire1"))
{
animator.SetBool("attack", true);
}
if (Input.GetButtonUp("Fire1"))
{
animator.SetBool("attack", false);
}
}
void OnCollisionEnter2D (Collision2D Col)
{
if(Col.gameObject.tag == "Enemy"){
Enemy enemy = Col.transform.gameObject.GetComponentInParent(typeof(Enemy)) as Enemy;
if (enemy != null)
{
//if (damageable = true)
//{
enemy.TakeDamage((int)damage);
//damageable = false;
// }
if(enemy.Died == true)
{
}
}
}
}
IEnumerator takeDamage()
{
if (damageable == false)
{
yield return new WaitForSeconds((int)delaytime);
damageable = true;
}
}
}
Thanks in advance!