質問編集履歴

1

Rotetoのコード追加

2022/09/09 03:05

投稿

tttooo
tttooo

スコア0

test CHANGED
File without changes
test CHANGED
@@ -17,6 +17,54 @@
17
17
  ```
18
18
  警告文が、そんなスクリプトは存在しません、と言っているのだと思います。
19
19
 
20
+ ```C#
21
+ using System;
22
+ using FlutterUnityIntegration;
23
+ using UnityEngine;
24
+ using UnityEngine.EventSystems;
25
+
26
+ public class Rotate : MonoBehaviour, IEventSystemHandler
27
+ {
28
+ [SerializeField]
29
+ Vector3 RotateAmount;
30
+
31
+ // Start is called before the first frame update
32
+ void Start()
33
+ {
34
+ RotateAmount = new Vector3(0, 0, 0);
35
+ }
36
+
37
+ // Update is called once per frame
38
+ void Update()
39
+ {
40
+ gameObject.transform.Rotate(RotateAmount * Time.deltaTime * 120);
41
+
42
+ for (int i = 0; i < Input.touchCount; ++i)
43
+ {
44
+ if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
45
+ {
46
+ var hit = new RaycastHit();
47
+
48
+ Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
49
+
50
+ if (Physics.Raycast(ray, out hit))
51
+ {
52
+ // This method is used to send data to Flutter
53
+ UnityMessageManager.Instance.SendMessageToFlutter("The cube feels touched.");
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ // This method is called from Flutter
60
+ public void SetRotationSpeed(String message)
61
+ {
62
+ float value = float.Parse(message);
63
+ RotateAmount = new Vector3(value, value, value);
64
+ }
65
+ }
66
+ ```
67
+
20
68
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-09-07/778dcb74-c6f1-45b5-bbab-bbb8248849af.png)
21
69
 
22
70
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-09-07/6c5518d8-e4ff-488a-8c94-34c8d40af4a6.png)