質問編集履歴

2

コードを開示した方が良いという指摘から

2021/08/30 03:59

投稿

Unagiwani
Unagiwani

スコア6

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,88 @@
10
10
 
11
11
 
12
12
 
13
+ ## 当該のソースコード
14
+
15
+ ```C#
16
+
17
+ using UnityEngine;
18
+
19
+
20
+
21
+ public class CubeRotate : MonoBehaviour
22
+
23
+ {
24
+
25
+ public GameObject obj; //回転させるもの
26
+
27
+ private Vector2 sPos;
28
+
29
+ private Quaternion sRot;
30
+
31
+ private float wid, hei;
32
+
33
+ private float tx, ty;
34
+
35
+
36
+
37
+ void Start()
38
+
39
+ {
40
+
41
+ wid = Screen.width;
42
+
43
+ hei = Screen.height;
44
+
45
+ }
46
+
47
+
48
+
49
+ void Update()
50
+
51
+ {
52
+
53
+ if (Input.touchCount == 1)
54
+
55
+ {
56
+
57
+ Touch touch = Input.GetTouch(0);
58
+
59
+ if (touch.phase == TouchPhase.Began)
60
+
61
+ {
62
+
63
+ sPos = touch.position;
64
+
65
+ sRot = obj.transform.rotation;
66
+
67
+ }
68
+
69
+ else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
70
+
71
+ {
72
+
73
+ tx = (touch.position.x - sPos.x) / wid;
74
+
75
+ ty = (touch.position.y - sPos.y) / hei;
76
+
77
+ obj.transform.rotation = sRot;
78
+
79
+ Vector3 vec = new Vector3(90 * ty, -90 * tx, 0);
80
+
81
+ obj.transform.Rotate(vec, Space.World);
82
+
83
+ }
84
+
85
+ }
86
+
87
+ }
88
+
89
+ }
90
+
91
+ ```
92
+
93
+
94
+
13
95
  ## 環境
14
96
 
15
97
  unity 2020.3.15f2

1

誤字の修正

2021/08/30 03:59

投稿

Unagiwani
Unagiwani

スコア6

test CHANGED
@@ -1 +1 @@
1
- Unity[3D] 立方体の最初にクリックした場所を掴んで回すような操作を実現したい
1
+ Unity[3D] 立方体のクリックした場所を掴んで回すような操作を実現したい
test CHANGED
File without changes