Instantiate

hey everyone!

I’m getting a problem with my code… I’ve told it to instantiate a “bomb blast” when space is hit but it doesn’t… It only does it when the game starts up and never again… Also the bomb itself isn’t destroyed so yeah… Here’s the code everyone and thanks for the help!

public class Boom3 : MonoBehaviour {

	public GameObject boom;
	public Transform boomb;

	void Update () {
		if (MotherBomb.bombnum == 3) {
			if (Input.GetKeyDown ("space")) {
				Instantiate (boom, boomb.position, boomb.rotation);
				Destroy (gameObject);
			}
		}
	}
}

Try replacing
if (Input.GetKeyDown (“space”))
with

if (Input.GetKeyDown (KeyCode.space))

Your destroy function is destroying the object that instantiates the bomb and not the bomb itself. Add a script to the bomb prefab that destroys it after a certain time. Subtract time.deltatime from some float in update. Have an if statement in update that destroys the gameobject if the float is equal to or less than zero.

My guess is you are destroying the gameObject that this script is attached to before it can call Instantiate. Therefore it never calls Instantiate.