回答編集履歴
1
補足
test
CHANGED
@@ -13,3 +13,97 @@
|
|
13
13
|
KeyCode
|
14
14
|
|
15
15
|
[https://docs.unity3d.com/ja/current/ScriptReference/KeyCode.html](https://docs.unity3d.com/ja/current/ScriptReference/KeyCode.html)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#追記
|
20
|
+
|
21
|
+
2点修正が必要です。そもそもまずUnityEngineのUsingが外れてるのでつけます。
|
22
|
+
|
23
|
+
あとはKeyCode指定のときは大文字のGを使ってください
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```cs
|
28
|
+
|
29
|
+
using System.Collections;
|
30
|
+
|
31
|
+
using System.Collections.Generic;
|
32
|
+
|
33
|
+
using UnityEngine.UI;
|
34
|
+
|
35
|
+
using UnityEngine;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
public class Tyutoriaru : MonoBehaviour {
|
40
|
+
|
41
|
+
// Start is called before the first frame update
|
42
|
+
|
43
|
+
void Start() {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
// Update is called once per frame
|
52
|
+
|
53
|
+
void Update() {
|
54
|
+
|
55
|
+
if (Input.GetKeyDown(KeyCode.G)) {
|
56
|
+
|
57
|
+
print("G key was pressed");
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
あとは表示非表示の処理を書くだけでやりたいことができると思います
|
70
|
+
|
71
|
+
```cs
|
72
|
+
|
73
|
+
using System.Collections;
|
74
|
+
|
75
|
+
using System.Collections.Generic;
|
76
|
+
|
77
|
+
using UnityEngine.UI;
|
78
|
+
|
79
|
+
using UnityEngine;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
public class Tyutoriaru : MonoBehaviour {
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
[SerializeField] GameObject panel; // 表示・非表示にしたいオブジェクトの参照をInspectorからアタッチ
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// Update is called once per frame
|
92
|
+
|
93
|
+
void Update() {
|
94
|
+
|
95
|
+
if (Input.GetKeyDown(KeyCode.G)) {
|
96
|
+
|
97
|
+
print("G key was pressed");
|
98
|
+
|
99
|
+
var isActive = panel.activeInHierarchy; // panelがアクティブか取得
|
100
|
+
|
101
|
+
panel.SetActive(!isActive); // 反転させる
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
```
|