Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / EnemyDebris.cs
@小李xl 小李xl on 3 Jun 2023 1 KB 引入Godot表格插件
  1.  
  2. using System.Collections;
  3. using Godot;
  4.  
  5. public partial class EnemyDebris : ActivityObject
  6. {
  7.  
  8. private GpuParticles2D _gpuParticles2D;
  9. public override void OnInit()
  10. {
  11. var frameCount = AnimatedSprite.SpriteFrames.GetFrameCount(AnimatorNames.Default);
  12. AnimatedSprite.Frame = Utils.RandomRangeInt(0, frameCount - 1);
  13.  
  14. Throw(
  15. Utils.RandomRangeInt(0, 16),
  16. Utils.RandomRangeInt(10, 60),
  17. new Vector2(Utils.RandomRangeInt(-25, 25), Utils.RandomRangeInt(-25, 25)),
  18. Utils.RandomRangeInt(-360, 360)
  19. );
  20.  
  21. StartCoroutine(EmitParticles());
  22. }
  23.  
  24. public IEnumerator EmitParticles()
  25. {
  26. var gpuParticles2D = GetNode<GpuParticles2D>("GPUParticles2D");
  27. gpuParticles2D.Emitting = true;
  28. yield return new WaitForSeconds(Utils.RandomRangeFloat(1f, 2.5f));
  29. gpuParticles2D.Emitting = false;
  30. yield return new WaitForSeconds(1);
  31. gpuParticles2D.QueueFree();
  32. EnableBehavior = false;
  33. Collision.QueueFree();
  34. }
  35. }