-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeapon_CircleBots_Scr.cs
78 lines (70 loc) · 2.46 KB
/
Weapon_CircleBots_Scr.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon_CircleBots_Scr : Weapon_Scr
{
private float lastBulletSpawnTime = 0f;
private int nextBotToShoot = 0;
[SerializeField] private GameObject bulletPrefab;
[SerializeField] private GameObject circleBotPrefab;
private List<Transform> botsTransforms = new List<Transform>();
private int curBotsCount;
protected override void Start()
{
base.Start();
curBotsCount = transform.childCount;
for (int i = 0; i < transform.childCount; i++)
{
botsTransforms.Add(transform.GetChild(i));
}
UpdateBotsRadialPositions();
}
private void Update()
{
transform.Rotate(transform.forward, -Player_Stats_Scr.CircleBots.rotationSpeed * Time.deltaTime, Space.Self);
if (lastBulletSpawnTime + Player_Stats_Scr.CircleBots.bulletSpawnDelay / curBotsCount < Time.time)
{
SpawnBullet();
lastBulletSpawnTime = Time.time;
}
}
private void SpawnBullet()
{
GameObject newBullet = Instantiate(bulletPrefab, botsTransforms[nextBotToShoot].position, Quaternion.identity); // TODO: ïîäïðàâèòü ÷òîá ñòðåëÿë îòêóäà íàäî
nextBotToShoot++;
if (nextBotToShoot >= botsTransforms.Count)
nextBotToShoot = 0;
}
private void UpdateBotsRadialPositions()
{
for (int i = 0; i < curBotsCount; i++)
{
botsTransforms[i].localPosition = Quaternion.AngleAxis(360 / curBotsCount * i, Vector3.forward) * Vector3.right * Player_Stats_Scr.CircleBots.circlingDistance;
botsTransforms[i].rotation = Quaternion.identity;
}
}
#region Upgrade Methods
public void AddBots(float numOfBotsToAdd)
{
for (int i = 0; i < numOfBotsToAdd; i++)
{
botsTransforms.Add(Instantiate(circleBotPrefab, transform).transform);
curBotsCount++;
}
UpdateBotsRadialPositions();
}
public void IncreaseCirclingRadius(float radiusIncrease)
{
Player_Stats_Scr.CircleBots.circlingDistance += radiusIncrease;
UpdateBotsRadialPositions();
}
public void IncreaseRotationSpeed(float speedIncrease)
{
Player_Stats_Scr.CircleBots.rotationSpeed += speedIncrease;
}
public void DecreaseShotDelay(float delayDecrease)
{
Player_Stats_Scr.CircleBots.bulletSpawnDelay -= delayDecrease;
}
#endregion
}