I'm trying to make it so when a Cactus is hit 3 times by a bullet it gets removed. I'm stuck here and don't what to do. (The cactus is removed as soon as it is touched 1 time and doesnt wait until it is down to 0 hearts. CactusHearts variable is set in the Cactus class)
Here's my code:
public void Break_Cactus()
{
if(this.isTouching(Cactus.class))
{
SandWorld.Cacti--;
//Greenfoot.playSound("")
getWorld().getObjects(Cactus.class).get(0).CactusHearts--;
if(getWorld().getObjects(Cactus.class).get(0).CactusHearts == 0)
{
this.removeTouching(Cactus.class);
}
else
{
}
}
}