Scriptum/Assets/Scripts/DealDamage.cs

40 lines
869 B
C#
Raw Permalink Normal View History

2022-06-09 21:51:48 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DealDamage : MonoBehaviour
{
private bool inRange;
private float timer = 0f;
private float waitTime = 0.35f;
private bool firstAttack = true;
void Update()
{
timer += Time.deltaTime;
if (timer >= 0.5f)
{
firstAttack = true;
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Enemy")
{
if (firstAttack == true)
{
collision.GetComponent<FollowingEnemy>().TakeDamage(1.0f);
firstAttack = false;
}
else if (timer >= waitTime)
{
collision.GetComponent<FollowingEnemy>().TakeDamage(1.0f);
timer = 0f;
}
}
}
}