Initial commit
This commit is contained in:
commit
c266d22f58
85 changed files with 1649 additions and 0 deletions
31
scripts/components/plants/Shooter.cs
Normal file
31
scripts/components/plants/Shooter.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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>();
|
||||
LevelController.Instance.Pools.Projectiles.AddChild(instance);
|
||||
instance.GlobalTransform = GlobalTransform;
|
||||
|
||||
if (instance is IProjectile projectile)
|
||||
{
|
||||
projectile.Line = _plantData.Line;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue