-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShooterContainer.cs
More file actions
112 lines (102 loc) · 2.74 KB
/
ShooterContainer.cs
File metadata and controls
112 lines (102 loc) · 2.74 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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShooterContainer : MonoBehaviour
{
private int rotSpeed = 30;
public int rotateZval;
private void Start()
{
StartCoroutine(ChangeDirectionRoutine());
}
// Update is called once per frame
void Update()
{
int TotalCP = PlayerPrefs.GetInt("TotalCP");
if (TotalCP >= 10 && TotalCP <= 20)
{
rotSpeed = 50;
}
else if (TotalCP >= 20 && TotalCP <= 30)
{
rotSpeed = 80;
}
else if (TotalCP >= 30)
{
rotSpeed = 120;
}
transform.Rotate(new Vector3(0, 0, rotateZval) * rotSpeed * Time.deltaTime);
ClampAngle(transform.rotation.z, -53, 53);
}
IEnumerator ChangeDirectionRoutine()
{
while (true)
{
int randNo = Random.Range(0, 2);
if (randNo == 0)
{
rotateZval = -1;
}
else if(randNo == 1)
{
rotateZval = 1;
}
int TotalCP = PlayerPrefs.GetInt("TotalCP");
if (TotalCP < 10)
{
yield return new WaitForSeconds(0.65f);
}
else if (TotalCP >= 10 && TotalCP <= 20)
{
yield return new WaitForSeconds(0.5f);
}
else if (TotalCP >= 20 && TotalCP <= 30)
{
yield return new WaitForSeconds(0.35f);
}
else if (TotalCP >= 30)
{
yield return new WaitForSeconds(0.2f);
}
}
}
public static float ClampAngle(float angle, float min, float max)
{
angle = Mathf.Repeat(angle, 360);
min = Mathf.Repeat(min, 360);
max = Mathf.Repeat(max, 360);
bool inverse = false;
var tmin = min;
var tangle = angle;
if (min > 180)
{
inverse = !inverse;
tmin -= 180;
}
if (angle > 180)
{
inverse = !inverse;
tangle -= 180;
}
var result = !inverse ? tangle > tmin : tangle < tmin;
if (!result)
angle = min;
inverse = false;
tangle = angle;
var tmax = max;
if (angle > 180)
{
inverse = !inverse;
tangle -= 180;
}
if (max > 180)
{
inverse = !inverse;
tmax -= 180;
}
result = !inverse ? tangle < tmax : tangle > tmax;
if (!result)
angle = max;
return angle;
}
}