31 lines
713 B
C#
31 lines
713 B
C#
using Godot;
|
|
|
|
// Shoot component of some plants
|
|
public partial class Shooter : Node2D
|
|
{
|
|
[Export] private PackedScene _projectile;
|
|
[Export] private Timer _timer;
|
|
|
|
private RuntimePlantData _plantData;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_plantData = GetParent<RuntimePlantData>();
|
|
}
|
|
|
|
|
|
public void Shoot()
|
|
{
|
|
if (_timer.TimeLeft > 0) return;
|
|
|
|
_timer.Start();
|
|
var instance = _projectile.Instantiate<Node2D>();
|
|
PoolContainer.Instance.Projectiles.AddChild(instance);
|
|
instance.GlobalTransform = GlobalTransform;
|
|
|
|
if (instance is IProjectile projectile)
|
|
{
|
|
projectile.Line = _plantData.Line;
|
|
}
|
|
}
|
|
}
|