回答編集履歴
2
追記
test
CHANGED
@@ -16,6 +16,8 @@
|
|
16
16
|
|
17
17
|
#### 2. Hierarchy上に`Event System`を生成
|
18
18
|
|
19
|
+
すでにある場合は生成する必要はありません。
|
20
|
+
|
19
21
|
![イメージ説明](e2e8dd52e9a9fabac2d5fc29da392965.png)
|
20
22
|
|
21
23
|
|
1
コードを変更
test
CHANGED
@@ -74,7 +74,7 @@
|
|
74
74
|
|
75
75
|
/// <summary>
|
76
76
|
|
77
|
-
/// 地面からどの程度浮か
|
77
|
+
/// 地面からどの程度浮かばせるか?
|
78
78
|
|
79
79
|
/// </summary>
|
80
80
|
|
@@ -86,7 +86,7 @@
|
|
86
86
|
|
87
87
|
/// </summary>
|
88
88
|
|
89
|
-
const float DragSpeed = 1
|
89
|
+
const float DragSpeed = 10f;
|
90
90
|
|
91
91
|
|
92
92
|
|
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
Rigidbody rigid;
|
96
96
|
|
97
|
-
bool is
|
97
|
+
bool isKinematic;
|
98
98
|
|
99
99
|
Camera cam;
|
100
100
|
|
@@ -114,111 +114,103 @@
|
|
114
114
|
|
115
115
|
tr = transform;
|
116
116
|
|
117
|
-
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
/// <summary>
|
122
|
+
|
123
|
+
/// ドラッグの開始
|
124
|
+
|
125
|
+
/// </summary>
|
126
|
+
|
127
|
+
/// <param name="eventData"></param>
|
128
|
+
|
129
|
+
public void OnBeginDrag(PointerEventData eventData)
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
// ドラッグ中は物理演算が働かないようにする
|
118
134
|
|
119
135
|
if (rigid != null)
|
120
136
|
|
121
137
|
{
|
122
138
|
|
123
|
-
is
|
139
|
+
isKinematic = rigid.isKinematic;
|
140
|
+
|
124
|
-
|
141
|
+
rigid.isKinematic = true;
|
142
|
+
|
125
|
-
}
|
143
|
+
}
|
126
|
-
|
144
|
+
|
127
|
-
}
|
145
|
+
}
|
128
|
-
|
129
|
-
|
130
|
-
|
146
|
+
|
147
|
+
|
148
|
+
|
131
|
-
/// <summary>
|
149
|
+
/// <summary>
|
132
|
-
|
150
|
+
|
133
|
-
/// ドラッグ
|
151
|
+
/// ドラッグ中
|
134
152
|
|
135
153
|
/// </summary>
|
136
154
|
|
137
155
|
/// <param name="eventData"></param>
|
138
156
|
|
139
|
-
public void On
|
157
|
+
public void OnDrag(PointerEventData eventData)
|
140
|
-
|
158
|
+
|
141
|
-
{
|
159
|
+
{
|
160
|
+
|
142
|
-
|
161
|
+
var ray = cam.ScreenPointToRay(eventData.position);
|
162
|
+
|
163
|
+
Vector3 pos = default;
|
164
|
+
|
165
|
+
if (plane.Raycast(ray, out float hit))
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
pos = ray.GetPoint(hit);
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
else if( hit < -1.0f )
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
pos = ray.GetPoint(-hit);
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
if (pos != default)
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
tr.position = Vector3.Lerp(tr.position, pos, DragSpeed * Time.deltaTime);
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
/// <summary>
|
196
|
+
|
197
|
+
/// ドラッグの終了
|
198
|
+
|
199
|
+
/// </summary>
|
200
|
+
|
201
|
+
/// <param name="eventData"></param>
|
202
|
+
|
203
|
+
public void OnEndDrag(PointerEventData eventData)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
143
|
-
// ドラッグ
|
207
|
+
// ドラッグ後は物理演算を元に戻す
|
144
208
|
|
145
209
|
if (rigid != null)
|
146
210
|
|
147
211
|
{
|
148
212
|
|
149
|
-
rigid.isKinematic = true;
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
/// <summary>
|
158
|
-
|
159
|
-
/// ドラッグ中
|
160
|
-
|
161
|
-
/// </summary>
|
162
|
-
|
163
|
-
/// <param name="eventData"></param>
|
164
|
-
|
165
|
-
public void OnDrag(PointerEventData eventData)
|
166
|
-
|
167
|
-
{
|
168
|
-
|
169
|
-
var ray = cam.ScreenPointToRay(eventData.position);
|
170
|
-
|
171
|
-
Vector3 pos = default;
|
172
|
-
|
173
|
-
if (plane.Raycast(ray, out float hit))
|
174
|
-
|
175
|
-
{
|
176
|
-
|
177
|
-
pos = ray.GetPoint(hit);
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
else if( hit < -1.0f )
|
182
|
-
|
183
|
-
{
|
184
|
-
|
185
|
-
pos = ray.GetPoint(-hit);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
if (pos != default)
|
192
|
-
|
193
|
-
{
|
194
|
-
|
195
|
-
tr.position = Vector3.Lerp(tr.position, pos, DragSpeed * Time.deltaTime);
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
/// <summary>
|
204
|
-
|
205
|
-
/// ドラッグの終了
|
206
|
-
|
207
|
-
/// </summary>
|
208
|
-
|
209
|
-
/// <param name="eventData"></param>
|
210
|
-
|
211
|
-
public void OnEndDrag(PointerEventData eventData)
|
212
|
-
|
213
|
-
{
|
214
|
-
|
215
|
-
// ドラッグ後は物理演算を元に戻す
|
216
|
-
|
217
|
-
if (rigid != null)
|
218
|
-
|
219
|
-
{
|
220
|
-
|
221
|
-
rigid.isKinematic = is
|
213
|
+
rigid.isKinematic = isKinematic;
|
222
214
|
|
223
215
|
}
|
224
216
|
|