40 lines
869 B
C#
40 lines
869 B
C#
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;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|