-
Notifications
You must be signed in to change notification settings - Fork 0
/
BossCombat.cs
106 lines (84 loc) · 2.55 KB
/
BossCombat.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCombat : MonoBehaviour
{
static public int attackDamage = 20;
static public int castDamage = 30;
public Vector3 attackOffset;
public float attackRange = 1f;
public LayerMask attackMask;
//Projectile Attack
public GameObject[] castSprits = new GameObject[8];
float radius, moveSpeed;
//Homing Spirit Attack
public GameObject HomingSpirit;
public Transform homingSource;
private void Start()
{
radius = 10f;
moveSpeed = 1.2f;
}
public void Attack()
{
Vector3 pos = transform.position;
pos += transform.right * attackOffset.x;
pos += transform.up * attackOffset.y;
Collider2D colInfo = Physics2D.OverlapCircle(pos, attackRange, attackMask);
if (colInfo != null)
{
colInfo.GetComponent<PlayerHealth>().TakeDamage(attackDamage);
}
}
public void CastAttackHandler(Animator animator)
{
StartCoroutine(CastAttackTimer(animator));
}
IEnumerator CastAttackTimer(Animator animator)
{
yield return new WaitForSeconds(0.5f);
int attackChoice = Random.Range(1, 2);
switch (attackChoice)
{
case 1:
if (BossHealth.isSecondPhaseActive)
{
animator.SetTrigger("RangedAttack1");
}
break;
case 2:
if (BossHealth.isThirdPhaseActive)
{
animator.SetTrigger("RangedAttack2");
}
break;
}
}
public void MultiCastAttack()
{
Vector2 castStartPoint = GetComponent<Transform>().position;
float angleStep = 360f / castSprits.Length;
float angle = 0f;
for (int i = 0; i <= castSprits.Length - 1; i++)
{
float projectileDirXposition = castStartPoint.x + Mathf.Sin((angle * Mathf.PI) / 180) * radius;
float projectileDirYposition = castStartPoint.y + Mathf.Cos((angle * Mathf.PI) / 180) * radius;
Vector2 projectileVector = new Vector2(projectileDirXposition, projectileDirYposition);
Vector2 projectileMoveDirection = (projectileVector - castStartPoint).normalized * moveSpeed;
Instantiate(castSprits[i], castStartPoint, Quaternion.identity);
castSprits[i].GetComponent<CastSpirits>().SetSpiritParams(projectileMoveDirection);
angle += angleStep;
}
}
public void HomingAttack()
{
Instantiate(HomingSpirit, homingSource.position, transform.rotation);
}
void OnDrawGizmosSelected()
{
Vector3 pos = transform.position;
pos += transform.right * attackOffset.x;
pos += transform.up * attackOffset.y;
Gizmos.DrawWireSphere(pos, attackRange);
}
}