質問編集履歴
6
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -140,7 +140,7 @@
|
|
140
140
|
|
141
141
|
void Start () {
|
142
142
|
|
143
|
-
StartCoroutine(ChangeCoroutine(cube,
|
143
|
+
StartCoroutine(ChangeCoroutine(cube, cube.transform.position.x, 5f, 3f));
|
144
144
|
|
145
145
|
}
|
146
146
|
|
5
補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -178,7 +178,7 @@
|
|
178
178
|
|
179
179
|
|
180
180
|
|
181
|
-
//
|
181
|
+
//調整。
|
182
182
|
|
183
183
|
go.transform.position = new Vector3(end, go.transform.position.y, go.transform.position.z);
|
184
184
|
|
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,7 +76,7 @@
|
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
-
### 追記
|
79
|
+
### 追記①
|
80
80
|
|
81
81
|
|
82
82
|
|
@@ -125,3 +125,87 @@
|
|
125
125
|
}
|
126
126
|
|
127
127
|
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
### 追記②
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
追記①のように変化させる値を引数で渡すコードは、実用的でなかったので、次のようなコード例を考えてみました。
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
```C#
|
140
|
+
|
141
|
+
void Start () {
|
142
|
+
|
143
|
+
StartCoroutine(ChangeCoroutine(cube, 1f, 5f, 3f));
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
// Update is called once per frame
|
150
|
+
|
151
|
+
void Update () {
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
IEnumerator ChangeCoroutine(GameObject go, float start, float end, float duration){
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
float t=0;
|
164
|
+
|
165
|
+
float x=0;
|
166
|
+
|
167
|
+
while(t<1){
|
168
|
+
|
169
|
+
x = Mathf.Lerp(start, end, t);
|
170
|
+
|
171
|
+
t += Time.deltaTime/duration;
|
172
|
+
|
173
|
+
go.transform.position = new Vector3(x, go.transform.position.y, go.transform.position.z);
|
174
|
+
|
175
|
+
yield return null;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
//tが1未満でwhile文から抜ける可能性がある為、調整。
|
182
|
+
|
183
|
+
go.transform.position = new Vector3(end, go.transform.position.y, go.transform.position.z);
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
経過時間が格納されているかログで確認しました。
|
194
|
+
|
195
|
+
```C#
|
196
|
+
|
197
|
+
float time = 0;
|
198
|
+
|
199
|
+
//3秒間、毎フレーム行う処理をwhile文の中に記述。
|
200
|
+
|
201
|
+
while(time < 3){
|
202
|
+
|
203
|
+
time += Time.deltaTime;
|
204
|
+
|
205
|
+
Debug.Log(time);
|
206
|
+
|
207
|
+
yield return null;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
```
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -108,9 +108,7 @@
|
|
108
108
|
|
109
109
|
Debug.Log(value);
|
110
110
|
|
111
|
-
|
111
|
+
yield return null;
|
112
|
-
|
113
|
-
yield return new WaitForSeconds(2);
|
114
112
|
|
115
113
|
}
|
116
114
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
追記。
test
CHANGED
File without changes
|
test
CHANGED
@@ -73,3 +73,57 @@
|
|
73
73
|
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
### 追記
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```C#
|
84
|
+
|
85
|
+
void Start () {
|
86
|
+
|
87
|
+
float i = 0;
|
88
|
+
|
89
|
+
StartCoroutine(ChangeCoroutine(i, 1f, 5f, 3f));
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
IEnumerator ChangeCoroutine(float value, float start, float end, float duration){
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
float t=0;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
while(t<1){
|
104
|
+
|
105
|
+
value = Mathf.Lerp(start, end, t);
|
106
|
+
|
107
|
+
t += Time.deltaTime/duration;
|
108
|
+
|
109
|
+
Debug.Log(value);
|
110
|
+
|
111
|
+
//yield return null;
|
112
|
+
|
113
|
+
yield return new WaitForSeconds(2);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
//tが1未満でwhile文から抜ける可能性がある為、調整。
|
120
|
+
|
121
|
+
value = end;
|
122
|
+
|
123
|
+
Debug.Log(value);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|