teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

Textアタッチしているスクリプト

2019/12/25 03:10

投稿

uty
uty

スコア6

title CHANGED
File without changes
body CHANGED
@@ -15,4 +15,79 @@
15
15
  Panelがドラッグできないようにするためには,
16
16
  どうすればいいですか?
17
17
 
18
- ご教授のほどよろしくお願いいたします.
18
+ ご教授のほどよろしくお願いいたします.
19
+
20
+ ###追記
21
+ Textにアタッチしているスクリプトです.
22
+ [このサイト](https://qiita.com/ayumegu/items/c07594f408363f73008c)を参考にしています.
23
+ ```C#
24
+ using System.Collections;
25
+ using System.Collections.Generic;
26
+ using UnityEngine;
27
+ using TMPro;
28
+ using UnityEngine.EventSystems;
29
+
30
+
31
+ public class drag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
32
+ {
33
+
34
+
35
+ private GameObject dragObject;
36
+
37
+ //ドラッグするオブジェクト
38
+ public GameObject target;
39
+ //Panel
40
+ public GameObject Panel;
41
+
42
+ // Start is called before the first frame update
43
+ void Start()
44
+ {
45
+
46
+ }
47
+
48
+ // Update is called once per frame
49
+ void Update()
50
+ {
51
+
52
+ }
53
+
54
+
55
+
56
+
57
+ public void OnBeginDrag(PointerEventData pointerEventData)
58
+ {
59
+ DragObject();
60
+ dragObject.transform.position = new Vector3(pointerEventData.position.x ,pointerEventData.position.y,dragObject.transform.position.z);
61
+
62
+
63
+ }
64
+
65
+ public void OnDrag(PointerEventData pointerEventData)
66
+ {
67
+ dragObject.transform.position = new Vector3(pointerEventData.position.x, pointerEventData.position.y, dragObject.transform.position.z);
68
+
69
+ }
70
+
71
+ public void OnEndDrag(PointerEventData pointerEventData)
72
+ {
73
+ Destroy(dragObject);
74
+
75
+ }
76
+
77
+
78
+ //ドラッグするオブジェクトのクローンの生成
79
+ private void DragObject()
80
+ {
81
+
82
+ dragObject = Instantiate(target, target.transform.position, Quaternion.identity);
83
+ dragObject.transform.SetParent(Panel.transform);
84
+ dragObject.transform.SetAsLastSibling();
85
+ dragObject.transform.localScale = target.transform.localScale;
86
+
87
+
88
+
89
+
90
+ }
91
+
92
+ }
93
+ ```