63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
using Godot;
|
|
|
|
public partial class Projectile : Node3D
|
|
{
|
|
[Export]
|
|
public double Cooldown { get; protected set; }
|
|
|
|
[Export]
|
|
private AudioStream _soundEffect;
|
|
|
|
[Export]
|
|
protected float _projectileSpeed = 1f;
|
|
|
|
[Export]
|
|
public bool HasRotation = false;
|
|
|
|
private bool isDeleted = false;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
Speed = _projectileSpeed;
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
var pathFollow = GetNode<PathFollow3D>("PathFollow3D");
|
|
pathFollow.Progress += Speed * (float)delta;
|
|
if (pathFollow.ProgressRatio > 0.98f)
|
|
Delete();
|
|
}
|
|
|
|
public void OnProjectileHit(Node node)
|
|
{
|
|
if (node is BasicEnemy basicEnemy)
|
|
basicEnemy.Call(BasicEnemy.MethodName.OnEnemyHit, node);
|
|
Delete();
|
|
}
|
|
|
|
public void OnPlayerHit(Node node)
|
|
{
|
|
SetPhysicsProcess(false);
|
|
|
|
if (node is Character character && character.HasMethod(Character.MethodName.OnHit))
|
|
{
|
|
GD.Print("Player hit: " + character.Name);
|
|
character.Call(Character.MethodName.OnHit, this);
|
|
}
|
|
|
|
QueueFree();
|
|
}
|
|
|
|
public void Delete()
|
|
{
|
|
if (!isDeleted)
|
|
{
|
|
isDeleted = true;
|
|
QueueFree();
|
|
}
|
|
}
|
|
|
|
public float Speed { get; private set; }
|
|
}
|