回答編集履歴
1
補足
answer
CHANGED
@@ -5,4 +5,51 @@
|
|
5
5
|
[https://docs.unity3d.com/ja/current/ScriptReference/Input.GetKeyDown.html](https://docs.unity3d.com/ja/current/ScriptReference/Input.GetKeyDown.html)
|
6
6
|
|
7
7
|
KeyCode
|
8
|
-
[https://docs.unity3d.com/ja/current/ScriptReference/KeyCode.html](https://docs.unity3d.com/ja/current/ScriptReference/KeyCode.html)
|
8
|
+
[https://docs.unity3d.com/ja/current/ScriptReference/KeyCode.html](https://docs.unity3d.com/ja/current/ScriptReference/KeyCode.html)
|
9
|
+
|
10
|
+
#追記
|
11
|
+
2点修正が必要です。そもそもまずUnityEngineのUsingが外れてるのでつけます。
|
12
|
+
あとはKeyCode指定のときは大文字のGを使ってください
|
13
|
+
|
14
|
+
```cs
|
15
|
+
using System.Collections;
|
16
|
+
using System.Collections.Generic;
|
17
|
+
using UnityEngine.UI;
|
18
|
+
using UnityEngine;
|
19
|
+
|
20
|
+
public class Tyutoriaru : MonoBehaviour {
|
21
|
+
// Start is called before the first frame update
|
22
|
+
void Start() {
|
23
|
+
|
24
|
+
}
|
25
|
+
|
26
|
+
// Update is called once per frame
|
27
|
+
void Update() {
|
28
|
+
if (Input.GetKeyDown(KeyCode.G)) {
|
29
|
+
print("G key was pressed");
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
あとは表示非表示の処理を書くだけでやりたいことができると思います
|
36
|
+
```cs
|
37
|
+
using System.Collections;
|
38
|
+
using System.Collections.Generic;
|
39
|
+
using UnityEngine.UI;
|
40
|
+
using UnityEngine;
|
41
|
+
|
42
|
+
public class Tyutoriaru : MonoBehaviour {
|
43
|
+
|
44
|
+
[SerializeField] GameObject panel; // 表示・非表示にしたいオブジェクトの参照をInspectorからアタッチ
|
45
|
+
|
46
|
+
// Update is called once per frame
|
47
|
+
void Update() {
|
48
|
+
if (Input.GetKeyDown(KeyCode.G)) {
|
49
|
+
print("G key was pressed");
|
50
|
+
var isActive = panel.activeInHierarchy; // panelがアクティブか取得
|
51
|
+
panel.SetActive(!isActive); // 反転させる
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
```
|