-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDamageCollider.cs
More file actions
52 lines (44 loc) · 1.24 KB
/
DamageCollider.cs
File metadata and controls
52 lines (44 loc) · 1.24 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageCollider : MonoBehaviour
{
Collider damageCollider;
public bool damagePlayer = true;
public bool damageEnemy = true;
public int weaponDamage = 2;
private void Awake()
{
damageCollider = GetComponent<Collider>();
damageCollider.gameObject.SetActive(true);
damageCollider.isTrigger = true;
damageCollider.enabled = false;
}
public void EnableDamageCollider()
{
damageCollider.enabled = true;
}
public void DisableDamageCollider()
{
damageCollider.enabled = false;
}
private void OnTriggerEnter(Collider collision)
{
if(damagePlayer && collision.tag == "Player")
{
PlayerStats playerStats = collision.GetComponent<PlayerStats>();
if(playerStats != null)
{
playerStats.TakeDamage(weaponDamage);
}
}
if (damageEnemy && collision.tag == "Enemy")
{
EnemyStats enemyStats = collision.GetComponent<EnemyStats>();
if (enemyStats != null)
{
enemyStats.TakeDamage(weaponDamage);
}
}
}
}