2022-06-04 13:59:18 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class TakingDamage : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
private bool inRange = false;
|
|
|
|
public GameObject other;
|
|
|
|
private bool firstAttack = false;
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
{
|
2022-06-06 16:21:26 +02:00
|
|
|
if (collision.tag == "PlayerHitbox")
|
2022-06-04 13:59:18 +02:00
|
|
|
{
|
|
|
|
inRange = true;
|
|
|
|
firstAttack = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
inRange = false;
|
|
|
|
timer = 0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
private float timer = 0f;
|
|
|
|
private float waitTime = 1.0f;
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (inRange == true)
|
|
|
|
{
|
|
|
|
if(firstAttack == false)
|
|
|
|
{
|
|
|
|
if(timer >= 0.15f)
|
|
|
|
{
|
|
|
|
firstAttack = true;
|
|
|
|
other.GetComponent<Player>().TakeDamage(1.0f);
|
|
|
|
timer = 0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (timer >= waitTime)
|
|
|
|
{
|
|
|
|
timer = 0f;
|
|
|
|
other.GetComponent<Player>().TakeDamage(1.0f);
|
|
|
|
}
|
|
|
|
timer += Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|