Try to reference Rigid Body

Hi I am try to reference the Rigid Body within my code, currently my code is attached to the Main Camera, and I have it so the player is able to move the character using the GUI Buttons.

However when I go onto actually spawn my character in by pressing the spawn button the character spawns, but the Move buttons do not make the duplicated character move?

The code I am using can be seen below

using UnityEngine;
using System.Collections;

public class GUIControls : MonoBehaviour {

	public Transform prefab;
	public Rigidbody MalePirate;

	//public GameObject Cube;
	//public GameObject Cube2;

	void Start() {
		//Reference your player's rigidbody component at the "Start" of the game
		MalePirate = GameObject.Find("MalePirate").GetComponent<Rigidbody>();
	}

	void OnGUI()
	{
		if (GUI.Button (new Rect (10, 10, 150, 100), "Move The Cube Left")) 
		{
			MalePirate.AddForce (Vector3.right * 50);
			//Cube2.GetComponent<Rigidbody>().AddForce(Vector3.left*50);
		}


		if (GUI.Button (new Rect (200, 10, 150, 100), "Move The Cube Right")) 
		{
			MalePirate.AddForce (Vector3.left * 50);
			//Cube2.GetComponent<Rigidbody>().AddForce(Vector3.right*50);
		}

		if (GUI.Button (new Rect (400, 10, 150, 100), "Spawn Cube"))
		{

			{
				Rigidbody.Instantiate (prefab, new Vector3 (-4, 0, 2), Quaternion.identity);
			}
		}

	}
}

As well as this I am also getting the following error:

‘NullReferenceException: Object reference not set to an instance of an object GUIControls.Start () (at Assets/Scripts/GUIControls.cs:14)’

And I have no idea what I need to reference or attach as for as far as I can see everything is already attached

Any help would be appreciated greatly, by the way yes I have tried googling I have been doing so for the past 2 days, but still can not see the issue.

Ok well if i am understanding what you want to do is be able to spawn more of those pirates and then move all the pirates.

  1. make a empty game object
  2. Drag the priate and or cube under the empty game object (Parent it)

So heres some code

var EmptyGameObject : GameObject;
//GameObject EmptyGameObject;
function OnGui(){
if (Move Left Button) {
EmptyGameObject.transform.position.x -= 1;
}
if (Move Right Button) {
EmptyGameObject.transform.position.x += 1;
}
if (Spawn) {
var Obj : GameObject = Instantiate(Crap in here);
Obj.transform.parent = EmptyGameObject;
}
}

Now they should move together