質問編集履歴

3

コードの追加

2021/01/04 23:51

投稿

shir
shir

スコア1

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,381 @@
23
23
 
24
24
 
25
25
  なぜこの様なエラーが出ているのでしょうか?そしてどうすればエラーが出なくなるのでしょうか?
26
+
27
+
28
+
29
+ ###### エフェクトに付いているスクリプトEmitParticlesOnLand
30
+
31
+ ```html
32
+
33
+ using System.Collections;
34
+
35
+ using System.Collections.Generic;
36
+
37
+ using UnityEngine;
38
+
39
+ using System.Reflection;
40
+
41
+
42
+
43
+ [RequireComponent(typeof(ParticleSystem))]
44
+
45
+ public class EmitParticlesOnLand : MonoBehaviour
46
+
47
+ {
48
+
49
+
50
+
51
+ public bool emitOnLand = true;
52
+
53
+ public bool emitOnEnemyDeath = true;
54
+
55
+
56
+
57
+ #if UNITY_TEMPLATE_PLATFORMER
58
+
59
+
60
+
61
+ ParticleSystem p;
62
+
63
+
64
+
65
+ void Start()
66
+
67
+ {
68
+
69
+ p = GetComponent<ParticleSystem>();
70
+
71
+
72
+
73
+ if (emitOnLand) {
74
+
75
+ Platformer.Gameplay.PlayerLanded.OnExecute += PlayerLanded_OnExecute;
76
+
77
+ void PlayerLanded_OnExecute(Platformer.Gameplay.PlayerLanded obj) {
78
+
79
+ p.Play();
80
+
81
+ }
82
+
83
+ }
84
+
85
+
86
+
87
+ if (emitOnEnemyDeath) {
88
+
89
+ Platformer.Gameplay.EnemyDeath.OnExecute += EnemyDeath_OnExecute;
90
+
91
+ void EnemyDeath_OnExecute(Platformer.Gameplay.EnemyDeath obj) {
92
+
93
+ p.Play();
94
+
95
+ }
96
+
97
+ }
98
+
99
+
100
+
101
+ }
102
+
103
+
104
+
105
+ #endif
106
+
107
+
108
+
109
+ }
110
+
111
+
112
+
113
+ ```
114
+
115
+
116
+
117
+ ###### プレイヤーに付いているスクリプトPlayerController.cs
118
+
119
+ ```html
120
+
121
+ using System.Collections;
122
+
123
+ using System.Collections.Generic;
124
+
125
+ using UnityEngine;
126
+
127
+ using Platformer.Gameplay;
128
+
129
+ using static Platformer.Core.Simulation;
130
+
131
+ using Platformer.Model;
132
+
133
+ using Platformer.Core;
134
+
135
+
136
+
137
+ namespace Platformer.Mechanics
138
+
139
+ {
140
+
141
+ /// <summary>
142
+
143
+ /// This is the main class used to implement control of the player.
144
+
145
+ /// It is a superset of the AnimationController class, but is inlined to allow for any kind of customisation.
146
+
147
+ /// </summary>
148
+
149
+ public class PlayerController : KinematicObject
150
+
151
+ {
152
+
153
+ public AudioClip jumpAudio;
154
+
155
+ public AudioClip respawnAudio;
156
+
157
+ public AudioClip ouchAudio;
158
+
159
+
160
+
161
+ /// <summary>
162
+
163
+ /// Max horizontal speed of the player.
164
+
165
+ /// </summary>
166
+
167
+ public float maxSpeed = 7;
168
+
169
+ /// <summary>
170
+
171
+ /// Initial jump velocity at the start of a jump.
172
+
173
+ /// </summary>
174
+
175
+ public float jumpTakeOffSpeed = 7;
176
+
177
+
178
+
179
+ public JumpState jumpState = JumpState.Grounded;
180
+
181
+ private bool stopJump;
182
+
183
+ /*internal new*/ public Collider2D collider2d;
184
+
185
+ /*internal new*/ public AudioSource audioSource;
186
+
187
+ public Health health;
188
+
189
+ public bool controlEnabled = true;
190
+
191
+
192
+
193
+ bool jump;
194
+
195
+ Vector2 move;
196
+
197
+ SpriteRenderer spriteRenderer;
198
+
199
+ internal Animator animator;
200
+
201
+ readonly PlatformerModel model = Simulation.GetModel<PlatformerModel>();
202
+
203
+
204
+
205
+ public Bounds Bounds => collider2d.bounds;
206
+
207
+
208
+
209
+ void Awake()
210
+
211
+ {
212
+
213
+ health = GetComponent<Health>();
214
+
215
+ audioSource = GetComponent<AudioSource>();
216
+
217
+ collider2d = GetComponent<Collider2D>();
218
+
219
+ spriteRenderer = GetComponent<SpriteRenderer>();
220
+
221
+ animator = GetComponent<Animator>();
222
+
223
+ }
224
+
225
+
226
+
227
+ protected override void Update()
228
+
229
+ {
230
+
231
+ if (controlEnabled)
232
+
233
+ {
234
+
235
+ move.x = Input.GetAxis("Horizontal");
236
+
237
+ if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump"))
238
+
239
+ jumpState = JumpState.PrepareToJump;
240
+
241
+ else if (Input.GetButtonUp("Jump"))
242
+
243
+ {
244
+
245
+ stopJump = true;
246
+
247
+ Schedule<PlayerStopJump>().player = this;
248
+
249
+ }
250
+
251
+ }
252
+
253
+ else
254
+
255
+ {
256
+
257
+ move.x = 0;
258
+
259
+ }
260
+
261
+ UpdateJumpState();
262
+
263
+ base.Update();
264
+
265
+ }
266
+
267
+
268
+
269
+ void UpdateJumpState()
270
+
271
+ {
272
+
273
+ jump = false;
274
+
275
+ switch (jumpState)
276
+
277
+ {
278
+
279
+ case JumpState.PrepareToJump:
280
+
281
+ jumpState = JumpState.Jumping;
282
+
283
+ jump = true;
284
+
285
+ stopJump = false;
286
+
287
+ break;
288
+
289
+ case JumpState.Jumping:
290
+
291
+ if (!IsGrounded)
292
+
293
+ {
294
+
295
+ Schedule<PlayerJumped>().player = this;
296
+
297
+ jumpState = JumpState.InFlight;
298
+
299
+ }
300
+
301
+ break;
302
+
303
+ case JumpState.InFlight:
304
+
305
+ if (IsGrounded)
306
+
307
+ {
308
+
309
+ Schedule<PlayerLanded>().player = this;
310
+
311
+ jumpState = JumpState.Landed;
312
+
313
+ }
314
+
315
+ break;
316
+
317
+ case JumpState.Landed:
318
+
319
+ jumpState = JumpState.Grounded;
320
+
321
+ break;
322
+
323
+ }
324
+
325
+ }
326
+
327
+
328
+
329
+ protected override void ComputeVelocity()
330
+
331
+ {
332
+
333
+ if (jump && IsGrounded)
334
+
335
+ {
336
+
337
+ velocity.y = jumpTakeOffSpeed * model.jumpModifier;
338
+
339
+ jump = false;
340
+
341
+ }
342
+
343
+ else if (stopJump)
344
+
345
+ {
346
+
347
+ stopJump = false;
348
+
349
+ if (velocity.y > 0)
350
+
351
+ {
352
+
353
+ velocity.y = velocity.y * model.jumpDeceleration;
354
+
355
+ }
356
+
357
+ }
358
+
359
+
360
+
361
+ if (move.x > 0.01f)
362
+
363
+ spriteRenderer.flipX = false;
364
+
365
+ else if (move.x < -0.01f)
366
+
367
+ spriteRenderer.flipX = true;
368
+
369
+
370
+
371
+ animator.SetBool("grounded", IsGrounded);
372
+
373
+ animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed);
374
+
375
+
376
+
377
+ targetVelocity = move * maxSpeed;
378
+
379
+ }
380
+
381
+
382
+
383
+ public enum JumpState
384
+
385
+ {
386
+
387
+ Grounded,
388
+
389
+ PrepareToJump,
390
+
391
+ Jumping,
392
+
393
+ InFlight,
394
+
395
+ Landed
396
+
397
+ }
398
+
399
+ }
400
+
401
+ }
402
+
403
+ ```

2

エラーコードをコードの表示内に

2021/01/04 23:51

投稿

shir
shir

スコア1

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,15 @@
6
6
 
7
7
 
8
8
 
9
- しかし動画の方では3:48あたりでエフェクトを削除している時動画が編集でカットされているのでよく分からないのですが、自分の方で同じように削除したところMissingReferenceException The object of type ParticleSystem has been destroyed but you are still trying to access it.というエラーが出てその後に同じエフェクトを追加し直しても全く動作しなくなってしまいます。
9
+ しかし動画の方では3:48あたりでエフェクトを削除している時動画が編集でカットされているのでよく分からないのですが、自分の方で同じように削除したところ
10
+
11
+ ```html
12
+
13
+ MissingReferenceException The object of type ParticleSystem has been destroyed but you are still trying to access it.
14
+
15
+ ```
16
+
17
+ というエラーが出てその後に同じエフェクトを追加し直しても全く動作しなくなってしまいます。
10
18
 
11
19
 
12
20
 

1

リンクの追加

2021/01/04 20:19

投稿

shir
shir

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,6 @@
1
1
  現在Unityさんの公式動画
2
2
 
3
- https://youtu.be/kNBWKuk_KYY?t=210
3
+ [https://youtu.be/kNBWKuk_KYY?t=210](https://youtu.be/kNBWKuk_KYY?t=210)を見て実践しています。
4
-
5
- を見て実践しています。
6
4
 
7
5
  指定した時間のあたりですが、チュートリアルにあるエフェクトをプレイヤーオブジェクトに追加すると問題なく動作します。
8
6