質問編集履歴

2

コードを提示した

2021/11/10 13:57

投稿

AnimatorMasatoy
AnimatorMasatoy

スコア45

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,181 @@
21
21
 
22
22
 
23
23
  具体的な対処法も原因もわかりません...
24
+
25
+
26
+
27
+ ```PlayerController
28
+
29
+ using System.Collections;
30
+
31
+ using System.Collections.Generic;
32
+
33
+ using UnityEngine;
34
+
35
+ using UnityEngine.SceneManagement;
36
+
37
+
38
+
39
+ public class PlayerController : MonoBehaviour
40
+
41
+ {
42
+
43
+
44
+
45
+ public GameObject UICanvas;
46
+
47
+
48
+
49
+ public static bool IsAFK = false;
50
+
51
+ int AFKTimer = 0;
52
+
53
+
54
+
55
+ // Start is called before the first frame update
56
+
57
+ void Start()
58
+
59
+ {}
60
+
61
+ void FixedUpdate()
62
+
63
+ {
64
+
65
+
66
+
67
+ if(!IsAFK && !Input.GetButtonDown("Jump")){
68
+
69
+ AFKTimer++;
70
+
71
+ }
72
+
73
+ //Debug.Log(AFKTimer);
74
+
75
+ if(AFKTimer > 60){
76
+
77
+ IsAFK = true;
78
+
79
+ AFKTimer = 0;
80
+
81
+ Debug.Log("放置");
82
+
83
+ GameManager uic = UICanvas.GetComponent<GameManager>();
84
+
85
+ uic.AFKBarEffect(1); //<-----コルーチン実行失敗
86
+
87
+ }
88
+
89
+
90
+
91
+ if(Input.GetButtonDown("Jump")){
92
+
93
+ if(IsAFK){
94
+
95
+ IsAFK = false;
96
+
97
+ Debug.Log("離脱");
98
+
99
+ GameManager uic = UICanvas.GetComponent<GameManager>();
100
+
101
+ uic.AFKBarEffect(2);
102
+
103
+ }
104
+
105
+ else{AFKTimer = 0;}
106
+
107
+ }
108
+
109
+ }
110
+
111
+ }
112
+
113
+
114
+
115
+ ```
116
+
117
+
118
+
119
+ ```GameManager
120
+
121
+ using System.Collections;
122
+
123
+ using System.Collections.Generic;
124
+
125
+ using UnityEngine;
126
+
127
+ using UnityEngine.UI;
128
+
129
+
130
+
131
+ public class GameManager : MonoBehaviour
132
+
133
+ {
134
+
135
+ //プレイヤー操作
136
+
137
+
138
+
139
+ public GameObject Player;
140
+
141
+
142
+
143
+ // Start is called before the first frame update
144
+
145
+ void Start()
146
+
147
+ {
148
+
149
+ Player = GameObject.FindGameObjectWithTag("Player");
150
+
151
+ }
152
+
153
+
154
+
155
+ // Update is called once per frame
156
+
157
+ void Update()
158
+
159
+ {}
160
+
161
+
162
+
163
+ public void AFKBarEffect(int mode){
164
+
165
+ if(mode == 1){
166
+
167
+ StartCoroutine( CorAFK() );
168
+
169
+ }
170
+
171
+ else{
172
+
173
+ StartCoroutine( CorBack() );
174
+
175
+ }
176
+
177
+ IEnumerator CorAFK(){
178
+
179
+ Debug.Log("コルーチン実行");
180
+
181
+ yield return new WaitForSeconds(0.1f);
182
+
183
+ Debug.Log("コルーチン実行");
184
+
185
+ }
186
+
187
+ IEnumerator CorBack(){
188
+
189
+ Debug.Log("コルーチン実行");
190
+
191
+ yield return new WaitForSeconds(0.1f);
192
+
193
+ Debug.Log("コルーチン実行");
194
+
195
+ }
196
+
197
+ }
198
+
199
+ }
200
+
201
+ ```

1

タイトル名を詳しく書いた

2021/11/10 13:57

投稿

AnimatorMasatoy
AnimatorMasatoy

スコア45

test CHANGED
@@ -1 +1 @@
1
- コルーチンの実行について
1
+ スクリプトから、別のスクリプトのメソッドを実行したときの、コルーチンの実行について
test CHANGED
File without changes