-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDamageArea.cs
More file actions
33 lines (27 loc) · 755 Bytes
/
DamageArea.cs
File metadata and controls
33 lines (27 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageArea : MonoBehaviour {
public int damage;
public bool active;
public GameObject ignore;
protected virtual void OnTriggerEnter2D(Collider2D other)
{
Damageable dmg = other.GetComponent<Damageable>();
if(active && dmg != null && !dmg.Dead && !transform.IsChildOf(other.transform))
{
if(ignore != null && other.transform.IsChildOf(ignore.transform))
return;
dmg.Damage(damage);
Collision();
}
}
protected virtual void Collision()
{
active = false;
}
public void SetActive(bool value)
{
active = value;
}
}