回答編集履歴
3
追記です。
answer
CHANGED
@@ -23,4 +23,33 @@
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
}
|
26
|
+
```
|
27
|
+
|
28
|
+
追記です。
|
29
|
+
|
30
|
+
|
31
|
+
```C#
|
32
|
+
using UnityEngine;
|
33
|
+
using UnityEngine.UI;
|
34
|
+
using UnityEngine.EventSystems;
|
35
|
+
|
36
|
+
public class ForceSelector : MonoBehaviour{
|
37
|
+
//自動選択されるボタン
|
38
|
+
public Selectable firstSelected;
|
39
|
+
|
40
|
+
void Start(){
|
41
|
+
if(firstSelected == null){
|
42
|
+
firstSelected = GetComponentInChildren<Selectable>();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
void OnEnable(){
|
47
|
+
ForceSelect();
|
48
|
+
}
|
49
|
+
|
50
|
+
public void ForceSelect(){
|
51
|
+
//firstSelectedを選択
|
52
|
+
EventSystem.current.SetSelectedGameObject(firstSelected.gameObject);
|
53
|
+
}
|
54
|
+
}
|
26
55
|
```
|
2
コメントを入れておきます。
answer
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
using UnityEngine.EventSystems;
|
6
6
|
|
7
7
|
public class ForceSelector : MonoBehaviour{
|
8
|
+
//自動選択されるボタン
|
8
9
|
public Selectable firstSelected;
|
9
10
|
|
10
11
|
void Start(){
|
@@ -12,8 +13,9 @@
|
|
12
13
|
firstSelected = GetComponentInChildren<Selectable>();
|
13
14
|
}
|
14
15
|
}
|
15
|
-
|
16
|
+
|
16
17
|
void Update(){
|
18
|
+
//EventSystemが何も選択していない場合、firstSelectedを選択
|
17
19
|
if (EventSystem.current.currentSelectedGameObject == null){
|
18
20
|
if(firstSelected!=null && firstSelected.gameObject.activeInHierarchy && firstSelected.interactable){
|
19
21
|
EventSystem.current.SetSelectedGameObject(firstSelected.gameObject);
|
1
これいらんわ
answer
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
void Start(){
|
11
11
|
if(firstSelected == null){
|
12
|
-
firstSelected = GetComponentInChildren<Selectable>(
|
12
|
+
firstSelected = GetComponentInChildren<Selectable>();
|
13
13
|
}
|
14
14
|
}
|
15
15
|
|