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.