NullReferenceException: Object reference not set to an instance of an object

Hello! Firstly I thank you in advance because I am really stuck.
I do not usually ask questions because usually I can find the solution by searching the internet.

Here is the error I get and this is my script.
NullReferenceException: Object reference not set to an instance of an object
Gun.Update () (at Assets/Gun.cs:43)

using UnityEngine;
using System.Collections;

public class Gun : MonoBehaviour {
	Vector3 position = Vector3.zero;
	public Rigidbody2D projectile;
	private Vector3 positionmouse = Vector3.zero;
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
		if ((Input.touchCount > 0 && 
		     Input.GetTouch(0).phase == TouchPhase.Began)) 
		{
			position.x = transform.position.x;
			position.y = transform.position.y;
			position.z = 0;
			Vector3 positiontouch = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, 0);
			Vector3 look = Camera.main.ScreenToWorldPoint(positiontouch);
			Rigidbody2D go = Instantiate (projectile, position, Quaternion.Euler(0,0,0)) as Rigidbody2D;
			go.transform.LookAt(look);    
			
			go.AddForce(go.transform.forward * 1100);
			
		}
		
		if((Input.GetButtonDown("Fire1")))
		{
			
			position.x = transform.position.x;
			position.y = transform.position.y;
			position.z = 0;
			positionmouse.x = Input.mousePosition.x;
			positionmouse.y = Input.mousePosition.y;
			
			Vector3 look = Camera.main.ScreenToWorldPoint(positionmouse);
			Rigidbody2D go = Instantiate (projectile, position, Quaternion.Euler(0,0,0)) as Rigidbody2D;
			go.transform.LookAt(look);    
			
			go.AddForce(go.transform.forward * 1100);
			
			
		}
		
	}
}

I modified my code many times to find the solution, but to no avail. The code above is the latest version, I have not been remodified.

Thank you in advance!

public Rigidbody2D projectile;

Rigidbody2D go = Instantiate (projectile, position, Quaternion.Euler(0,0,0)) as Rigidbody2D;

Do you have a Rigidbody assigned to this Public Variable before playing the Script?

Otherwise your trying to Instantiate a Null Object.

Thank you for your very quick answers!
From your advice, I changed the code like this:

if(look != null)
			{
				go.gameObject.transform.LookAt(look);    
				
				go.rigidbody2D.AddForce(go.transform.forward * 1100);
			}

I still have the same error… Projectile is indeed assigned to a rigidbody, and besides I shoot in the game, you can see the projectile appear before the crash the game.

alt text

The bomber is the “projectile”.

So, How can I fix this? Again thank you for your answers

You are mixing up the RigidBody2D and the GameObject references.

Replace line 43 to 45 with the following lines:

if (go == null) return; // oops, no object instantiated! bail out

go.gameObject.transform.LookAt(look);

go.AddForce(go.gameObject.transform.forward * 1100);