42 lines
998 B
C#
42 lines
998 B
C#
using Godot;
|
|
using Godot.Collections;
|
|
using System.Linq;
|
|
|
|
public partial class Projectile : Node3D
|
|
{
|
|
[Export]
|
|
public double Cooldown { get; protected set; }
|
|
|
|
[Export]
|
|
protected float _projectileSpeed = 1f;
|
|
|
|
[Export]
|
|
public AudioStream _soundEffect;
|
|
|
|
public Character ParentCharacter;
|
|
|
|
private Array<Path3D> _paths;
|
|
|
|
public override void _Ready()
|
|
{
|
|
Speed = _projectileSpeed;
|
|
var sfxPlayer = GetTree().Root.GetNode<AudioStreamPlayer>("Main/SFXPlayer");
|
|
sfxPlayer.Stream = _soundEffect;
|
|
sfxPlayer.Play();
|
|
_paths = new Array<Path3D>(GetChildren().OfType<Path3D>());
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
foreach (var paths in _paths)
|
|
{
|
|
var pathFollow = paths.GetChildren().OfType<PathFollow3D>().Single();
|
|
pathFollow.Progress += Speed * (float)delta;
|
|
if (pathFollow.ProgressRatio > 0.9f)
|
|
QueueFree();
|
|
}
|
|
}
|
|
|
|
public float Speed { get; private set; }
|
|
}
|