-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemyThrow.cs
123 lines (107 loc) · 3.35 KB
/
EnemyThrow.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyThrow : MonoBehaviour
{
public GameObject target;
public GameObject throwObject;
public float throwSpeed = 10.0f;
public Vector2 directionToThrow;
private bool isThrowing;
public float timeToThrow = 2.0f;
public float timeToThrowCounter;
public float timeBetweenThrows = 2.0f;
public float timeBetweenThrowsCounter;
public bool isArrow;
// Start is called before the first frame update
void Start()
{
target = FindObjectOfType<PlayerController>().gameObject;
timeToThrowCounter = timeToThrowCounter * Random.Range(0.5f, 1.5f);
timeBetweenThrowsCounter = timeBetweenThrows * Random.Range(0.5f, 1.5f);
}
// Update is called once per frame
void Update()
{
if (isThrowing)
{
timeToThrowCounter -= Time.deltaTime;
if (timeToThrowCounter < 0)
{
ThrowSomething();
isThrowing = false;
timeToThrowCounter = timeToThrow;
}
}
else
{
timeBetweenThrowsCounter -= Time.deltaTime;
if(timeBetweenThrowsCounter < 0)
{
isThrowing = true;
}
}
}
void ThrowSomething()
{
timeBetweenThrowsCounter = timeBetweenThrows;
timeToThrowCounter = timeToThrow;
directionToThrow = (target.transform.position - this.transform.position).normalized;
GameObject newThrow = Instantiate(throwObject, this.transform.position, this.transform.rotation) as GameObject;
Rigidbody2D newThrowRB = newThrow.GetComponent<Rigidbody2D>();
Skill spellSkill = newThrow.GetComponent<Skill>();
newThrowRB.velocity = directionToThrow * throwSpeed;
if (isArrow)
{
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.ATTACK2);
}
else
{
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.FIRE_SKILL);
}
if (directionToThrow.x > 0) //Mirando hacia la derecha
{
if (isArrow)
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, -45);
}
else
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, 90);
}
}
if (directionToThrow.x < 0) //Mirando hacia la Izquierda
{
if (isArrow)
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, -45);
}
else
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, 270);
}
}
if (directionToThrow.y > 0) //Mirando hacia arriba
{
if (isArrow)
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, -45);
}
else
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, 180);
}
}
if (directionToThrow.y < 0) //Mirando hacia la abajo
{
if (isArrow)
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, -45);
}
else
{
newThrow.transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
}
}