-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttack.cs
More file actions
68 lines (48 loc) · 1.51 KB
/
Copy pathAttack.cs
File metadata and controls
68 lines (48 loc) · 1.51 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEngine;
using System.Collections;
public class Attack : MonoBehaviour {
[SerializeField]
int damage = 1;
[SerializeField]
int attack_speed = 1;
[SerializeField]
string enemy;
[SerializeField]
float speed = 1;
[SerializeField]
float distance = 1;
float timeOfLastAttack;
[SerializeField]
float cooldownBetweenAttacks = 0.1f;
RotateOnKeyPressed scriptRotation;
Vector3 origin;
Character player;
bool attacked;
// Use this for initialization
void Start () {
scriptRotation = this.gameObject.GetComponentInParent<RotateOnKeyPressed>();
enemy = "Test_attack";
attacked = false;
origin = this.transform.position;
player = GetComponentInParent<Character>();
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire" + player.id) && !attacked) {
this.GetComponent<BoxCollider2D>().enabled = true;
//scriptRotation.RotateDown();
this.timeOfLastAttack = Time.time;
attacked = true;
}
if(attacked && Time.time > timeOfLastAttack + cooldownBetweenAttacks) {
this.GetComponent<BoxCollider2D>().enabled = false;
attacked = false;
//scriptRotation.RotateUp();
}
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
other.GetComponent<Health>().TakeDamage(damage);
}
}
}