Problems with sending multiple raycasts at once

Hi, I’m trying to make a simple prototype where I have a script attached to a gameObject, and that gameObject sends a raycast out in 5 different directions, up, down, left, right, and back.

I have the general idea of how this SHOULD work, and I have gotten it to work with just a single raycast, but it seems to throw an odd missing object reference exception when i make a raycast array.

public class Connector : MonoBehaviour
{
    public GameObject self;
    public RaycastHit[] hit;
   void Start()
    {
        GameObject self = gameObject.GetComponent<GameObject>();
        Physics.Raycast(self.transform.position, Vector3.up, out hit[0]);   // This is line 12
        Physics.Raycast(self.transform.position, Vector3.left, out hit[1]);
        Physics.Raycast(self.transform.position, Vector3.right, out hit[2]);
        Physics.Raycast(self.transform.position, Vector3.forward, out hit[3]);
        Physics.Raycast(self.transform.position, Vector3.back, out hit[4]);
        foreach (RaycastHit connect in hit)
        {
            if(connect.transform != null)
            {
                var joint = gameObject.AddComponent<FixedJoint>();
                joint.connectedBody = connect.transform.GetComponent<Rigidbody>();
            }
        }
    }
}

MissingComponentException: There is no ‘GameObject’ attached to the “Cube” game object, but a script is trying to access it.
You probably need to add a GameObject to the game object “Cube”. Or your script needs to check if the component is attached before using it.
Connector.Start () (at Assets/Assets/Script/Connector.cs:12)

Above ^ is the error I get when i use this code, and I tried to change self.transform.position (which I know is correct syntax) with just a transform location and a vector3, with the same error. I guess it could have something with the way i raycast, but I’m still learning so I’m not sure what Raycasting limits are.

first of all “gameobject” is NOT considered a component!!! Components attach to game objects. Also there is no need to look up a gameObject reference to itself.

secondly, when using arrays you need to initialize it by stating the length before you can do anything with it.

thirdly, with raycasting if you dont hit anything you can run into problems so it is recomended that you wrap raycasts like this into an “if” statement unless you are sure you will always get a hit.

	int i;
	public RaycastHit[] hit;
	public Vector3[] directions;
	FixedJoint joint;
	void Start(){
		hit = new RaycastHit[5];
		directions = new Vector3[]{Vector3.up, Vector3.left, Vector3.right, Vector3.forward, Vector3.back};
        i = hit.Length;while(i>0){i--;
		if(Physics.Raycast(transform.position, directions_, out hit*)){*_

joint = gameObject.AddComponent();
_ joint.connectedBody = hit*.transform.gameObject.GetComponent();
}else{print ("i didnt see anything in direction of "+directions.ToString());}
}
}*_