Scriptum/Assets/TakingDamage.cs

52 lines
1.1 KiB
C#
Raw Normal View History

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)
{
if (collision.tag == "PlayerHitbox")
{
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;
}
}
}