OneNote.cs
4.7 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//싱글노트
public class OneNote : MonoBehaviour
{
public float speed; //노트 떨어지는 속도
public bool isActive = false;//노트가 떨어질지 말지 결정
private bool isinitial=true; //active 될때마다 위치초기화하기위해서.
public int channel = 10;
//public int noteTime;
//굳이 생성될때마다 계산해서 넣을필요 없고 고정값 넣어줘도 되는애들
public float[] PGB_standard = new float[3]; //perfect, good, bad 's standard
public float destroyPositionX;
public float destroyPositionY;
public float sizeDif;
private int PGB_result;
private Vector3 waiting_loc = new Vector3(0.0f, 400.0f, 0.0f);
public GameObject Button; //노트가 떨어질 버튼
public GameObject controller;
void Start()
{
controller = GameObject.Find("NoteControler");
//고정값
float r = GetComponent<SphereCollider>().bounds.size.y;
PGB_standard[0] = r/3;
PGB_standard[1] = r/3*2;
PGB_standard[2] = r;
speed = 0.6f;
StartCoroutine(Move());
}
IEnumerator Move()
{
while (true)
{
if (isActive)
{
//처음 루프에 들어 왔으면
if (isinitial)
{
//채널에 의해 초기위치로 이동
Button = GameObject.Find("Button_" + channel);
destroyPositionX = Button.GetComponent<SphereCollider>().bounds.center.x - GetComponent<SphereCollider>().bounds.center.x;
destroyPositionY = Button.GetComponent<SphereCollider>().bounds.center.y - GetComponent<SphereCollider>().bounds.center.y;
sizeDif = Button.GetComponent<RectTransform>().rect.width * Button.transform.localScale.x;
isinitial = false;
}
if (transform.position.y > Button.transform.position.y - 0.5)
{
//Delta time : 1초/현재프레임 (보통 1초 60frame가정하지만 프레임 드랍 일어날수있으므로..)
transform.Translate(new Vector3(0, destroyPositionY, 0) * speed * Time.smoothDeltaTime);
transform.Translate(new Vector3(destroyPositionX, 0, 0) * speed * Time.smoothDeltaTime);
/* 사이즈 크게하기
Vector3 temp = transform.localScale;
temp = temp * sizeDif * speed * Time.smoothDeltaTime;
transform.localScale += temp; */
//그냥 rectTranform의 rect.width * scale 해서 내가 구해야겠다..
if (GetComponent<RectTransform>().rect.width * transform.localScale.x < sizeDif)
{ transform.localScale += new Vector3(0.1f, 0.1f, 0); }
}
else
{
PGB_result = 3;
controller.GetComponent<NoteControl>().PGBM_count[PGB_result] += 1; //미스카운트 업!
isActive = false;
}
}
else
{
if (!isinitial) {
//위치, 크기, initial flag 초기화.
transform.localPosition = waiting_loc;
transform.localScale = new Vector3(1, 1, 1);
isinitial = true;
}
}
yield return null;
}
}
public void TouchOccur()
{
//노트 좌표와 col좌표의 거리 계산
float distance = transform.position.y - Button.transform.position.y + transform.position.z - Button.transform.position.z;
if (distance < 0) { distance = -distance; }
if (distance < PGB_standard[1])
{
if (distance < PGB_standard[0])
{
//perfect
transform.GetComponent<Image>().color = Color.red;
Debug.Log(Time.time + "Perfect!");
PGB_result = 0;
}
else
{
//good
transform.GetComponent<Image>().color = Color.blue;
Debug.Log(Time.time + "Good!");
PGB_result = 1;
}
}
else
{
//bad
transform.GetComponent<Image>().color = Color.black;
Debug.Log(Time.time + "Bad!");
PGB_result = 2;
}
//Perfect/Good/Bad 카운트 업!
controller.GetComponent<NoteControl>().PGBM_count[PGB_result] += 1;
//해당쿨 종료!
isActive = false;
}
}