36 lines
769 B
C#
36 lines
769 B
C#
|
using Godot;
|
||
|
|
||
|
public partial class ThrowPillow : Node2D
|
||
|
{
|
||
|
[Export] public PackedScene pillow;
|
||
|
[Export] public Node pillowsNode;
|
||
|
[Export] public float RPM = 30f;
|
||
|
|
||
|
private float countdown = 0f;
|
||
|
|
||
|
// Called when the node enters the scene tree for the first time.
|
||
|
public override void _Ready()
|
||
|
{
|
||
|
pillow = GD.Load<PackedScene>("res://Scenes/Entities/pillow.tscn");
|
||
|
}
|
||
|
|
||
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
public override void _Process(double delta)
|
||
|
{
|
||
|
countdown -= (float)delta;
|
||
|
|
||
|
if (countdown > 0f)
|
||
|
return;
|
||
|
|
||
|
ShootPillow();
|
||
|
countdown = 60f / RPM;
|
||
|
}
|
||
|
|
||
|
private void ShootPillow()
|
||
|
{
|
||
|
var instance = pillow.Instantiate<Node2D>();
|
||
|
instance.GlobalPosition = GlobalPosition;
|
||
|
pillowsNode.AddChild(instance);
|
||
|
}
|
||
|
}
|