New answers tagged


I'm assuming you have paintComponent() already set up. You just need to use java.util.Timer and java.util.TimerTask. Timer is a class that runs a method implemented in TimerTask after a delay. TimerTask is an abstract class that allows you to implement the method that Timer runs. The function that Timer runs is TimerTask's run(). In TimerTask's run(), you ...


I found out that objects can be killed with body.lifespan Adding the line bullet.lifespan = 1000; in my fire() function fixed the problem


[DMGregory Rightly said but additionally] As you said you are loading the new scene then, you should not need to destroy the gameobject. If you are willing pause the game then, i will recommend you timeScale When timeScale is set to zero the game is basically paused if all your functions are frame rate independent. Your should look like this void ...


You are destroying the GameObject on which this script is running as soon as it collides with an enemy. (Destroy (gameObject);) That means it can't wait 3 seconds before loading the next scene - in 3 seconds' time, it will no longer exist and so it can't run any scripts at all! You'll want to either delay the object's destruction until after the delay, or ...


I suggest you use Invoke. It's pretty simple, and the documentation is pretty clear, too.

Top 50 recent answers are included