Getting invalid rank specifier when adding component from array

I’m trying to create a function which returns a gameobject with random scripts attached to it. What I’m trying to do is to get the scripts via prefabs and using AddComponent into them with this script.

using UnityEngine;
using System.Collections;

public class CreateRandom : MonoBehaviour {
	public GameObject EnemyShell;

	public ~~GameObject[]~~ MovementArray; //All these arrays shouldn't be of GameObject type. I made a mistake. It should be some way of getting different script names (Movement0,Movement1 etc.) into an array)
	public ~~GameObject[]~~ PatternArray;
	public ~~GameObject[]~~ BulletArray;

	private GameObject NewEnemy;

	GameObject CreateEnemy(){

		NewEnemy = EnemyShell;

		NewEnemy.AddComponent<MovementArray[Random.Range(int 0, MovementArray.Length-1)]>();
		NewEnemy.AddComponent<PatternArray[Random.Range(int 0, PatternArray.Length-1)]>();
		NewEnemy.AddComponent<BulletArray[Random.Range(int 0, BulletArray.Length-1)]>();

		return NewEnemy;
	}
}

However with this script, I’m getting the error “Invalid rank specifier: expected ‘,’ or ‘]’” when I try to use the AddComponent method.

GameObject.AddComponent is documented as adding a script to a GO. Your MovementArray is an array of GameObjects. You cannot add a GO as a component. I think you are suggesting that the GOs in the MovementArray all have different scripts applied. So, you’ll need to use GetComponents to get a list of the components on the GO. So, something like (not compiled, might have bugs, but you get the idea):

GameObject movementGO = MovementArray[Random.Range(int 0, MovementArray.Length-1)];
A[] a = movementGO.GetComponents<A>();
B[] b = movementGO.GetComponents<B>();
C[] c = movementGO.GetComponents<C>();

if (a.length > 0)
    NewEnemy.AddComponent<A>();
if (b.length > 0)
    NewEnemy.AddComponent<B>();
if (c.length > 0)
    NewEnemy.AddComponent<C>();

where your script components are called A, B and C. I suspect they have a more descriptive name (which will be the name of the class in your c# scripts.)