質問編集履歴
1
Textアタッチしているスクリプト
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,153 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
ご教授のほどよろしくお願いいたします.
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
###追記
|
40
|
+
|
41
|
+
Textにアタッチしているスクリプトです.
|
42
|
+
|
43
|
+
[このサイト](https://qiita.com/ayumegu/items/c07594f408363f73008c)を参考にしています.
|
44
|
+
|
45
|
+
```C#
|
46
|
+
|
47
|
+
using System.Collections;
|
48
|
+
|
49
|
+
using System.Collections.Generic;
|
50
|
+
|
51
|
+
using UnityEngine;
|
52
|
+
|
53
|
+
using TMPro;
|
54
|
+
|
55
|
+
using UnityEngine.EventSystems;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public class drag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
private GameObject dragObject;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//ドラッグするオブジェクト
|
74
|
+
|
75
|
+
public GameObject target;
|
76
|
+
|
77
|
+
//Panel
|
78
|
+
|
79
|
+
public GameObject Panel;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
// Start is called before the first frame update
|
84
|
+
|
85
|
+
void Start()
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
// Update is called once per frame
|
96
|
+
|
97
|
+
void Update()
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public void OnBeginDrag(PointerEventData pointerEventData)
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
DragObject();
|
118
|
+
|
119
|
+
dragObject.transform.position = new Vector3(pointerEventData.position.x ,pointerEventData.position.y,dragObject.transform.position.z);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
public void OnDrag(PointerEventData pointerEventData)
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
dragObject.transform.position = new Vector3(pointerEventData.position.x, pointerEventData.position.y, dragObject.transform.position.z);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
public void OnEndDrag(PointerEventData pointerEventData)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
Destroy(dragObject);
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
//ドラッグするオブジェクトのクローンの生成
|
156
|
+
|
157
|
+
private void DragObject()
|
158
|
+
|
159
|
+
{
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
dragObject = Instantiate(target, target.transform.position, Quaternion.identity);
|
164
|
+
|
165
|
+
dragObject.transform.SetParent(Panel.transform);
|
166
|
+
|
167
|
+
dragObject.transform.SetAsLastSibling();
|
168
|
+
|
169
|
+
dragObject.transform.localScale = target.transform.localScale;
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
```
|