Beeg checkin
This commit is contained in:
29
Enemies/Attacks/FireAtPlayer.cs
Normal file
29
Enemies/Attacks/FireAtPlayer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class FireAtPlayer : Timer
|
||||
{
|
||||
[Export]
|
||||
private Area3D _enemy;
|
||||
[Export]
|
||||
private PackedScene _fireProjectile;
|
||||
|
||||
public void OnFireAtPlayer()
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player");
|
||||
if (players.Any())
|
||||
{
|
||||
var convertedPlayers = players.Select(x => (Node3D)x);
|
||||
var target = convertedPlayers.OrderBy(x => _enemy.Position.DistanceTo(x.Position)).FirstOrDefault();
|
||||
var projectile = _fireProjectile.Instantiate<Projectile>() as EnemyBullet;
|
||||
projectile.Rotation = _enemy.Rotation;
|
||||
projectile.Position = _enemy.Position;
|
||||
GetParent().AddChild(projectile);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDied()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user