I'm currently making a game, and I want my character to shoot projectiles at the enemy. I'm facing an issue where when I click, the bullet doesn't fire. Here's my code so far:
public partial class PotatoCannon : Sprite2D
{
public Timer cooldown;
[Export]
public PackedScene boolet { get; set; }
public override void _Ready(){
cooldown = GetNode<Timer>("CannonCooldown");
cooldown.Autostart = false;
}
public override void _PhysicsProcess(double delta){
GD.Print(cooldown.TimeLeft);
LookAt(GetGlobalMousePosition());
RotationDegrees = Math.Abs(RotationDegrees);
if(RotationDegrees%360>=90.0 && RotationDegrees%360<=270.0){
FlipV = true;
}
else{
FlipV = false;
}
if(Input.IsActionJustPressed("shoot") && cooldown.TimeLeft == 0){
bullet Bullet = boolet.Instantiate<bullet>();
this.AddChild(Bullet);
cooldown.WaitTime = 1;
cooldown.Start();
}
}
}
oh and btw, the error message is
E 0:00:49:0157 PotatoCannon.cs:24 @ void PotatoCannon._PhysicsProcess(Double ): System.NullReferenceException: Object reference not set to an instance of an object.