forked from Myyyvothrr/1gam-dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon.cs
49 lines (38 loc) · 874 Bytes
/
weapon.cs
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
using UnityEngine;
using System.Collections;
public class weapon : MonoBehaviour
{
public int damage = 1;
public GameObject hit_prefab;
private bool _swinging = false;
public AudioClip _sound_hit;
void Start()
{
}
void Update()
{
}
void can_attack(bool attack)
{
_swinging = attack;
}
void set_damage(int amount)
{
damage = amount;
}
void OnCollisionEnter(Collision other)
{
if (_swinging && other.gameObject.tag.Equals("enemy"))
{
for (int i = 0; i < other.contacts.Length; ++i)
{
GameObject o = (GameObject)Instantiate(hit_prefab, other.contacts[i].point, Quaternion.LookRotation(other.contacts[i].normal));
o.transform.parent = other.transform;
Destroy(o, 2);
}
audio.PlayOneShot(_sound_hit);
other.gameObject.SendMessageUpwards("receive_damage", damage);
_swinging = false;
}
}
}