attaching a script at runtime to an element of GameObject array

Hello everyone,
I have just tried gameObject.AddComponent(“changeCursonOnHover”) to a prefab which
is added at runtime, and works fine!

When I use the array, everythings works fine except the model.AddComponent(“changeCursonOnHover”);

This script is attached to an empty gameObject and attached my prefabs to the array elements.

var arrayOfModels:GameObject;
function Start () {

var randomNumber:Number = Mathf.Round(Random.value * 2);

var model:GameObject = Instantiate(arrayOfModels[randomNumber], transform.position,transform.rotation) as GameObject;    
model.transform.parent = transform;
model.AddComponent("changeCursonOnHover");	

}

Please some help!

var arrayOfModels:GameObject;

It doesn’t look like you’re ever adding any elements to the array, so you’re likely instantiating Null. Add a test for null after the Instantiate() call and see if you get anything.