need help with instantiating for making a bullet shoot

trying to make it so when i hit “D” in game it shoots a bullet. I keep getting an error that says “An embedded statement may not be a declaration or labeled statement” here is my script:

using UnityEngine;
using System.Collections;

public class Creator : MonoBehaviour {

public Rigidbody ThePrefab;


// Use this for initialization
void Start () {
		

}

// Update is called once per frame
void Update () {
	if(Input.GetKey(KeyCode.D))
		Rigidbody instance;
		instance = Instantiate(thePrefab,transform.position, transform.rotation);

}

}

Surround your if statement with curly braces:

if(Input.GetKey(KeyCode.D))
{
       Rigidbody instance;
       instance = Instantiate(thePrefab,transform.position, transform.rotation);
}

Also, just so you don’t think I’m magic or anything, here’s how I solved this problem:

  1. I googled the exact text of the error “An embedded statement may not be a declaration or labeled statement”
  2. The top hit was from a .Net forums page. Someone else had the same problem.
  3. The answer in the forum was “if you have to declare something in an if statement, put it in curly braces”