How do I create / Instatiate an array of GameObjects in C#

I’m trying to create an array of “selectors” which will be used in a 3D menu. However, the following code is not working as I expected:

public int numSelectors = 5;
public GameObject[] selectorArr;
public Transform selector; //selected in the editor

// Use this for initialization
void Start () {
 selectorArr = new GameObject[numSelectors];
 for (int i = 0; i < numSelectors; i++){
 selectorArr *= (GameObject)Instantiate(selector, new Vector3((float)i,1,0), Quaternion.Euler(new Vector3(0,0,0))) as GameObject;*

selectorArr*.transform.localScale = new Vector3(1,1,1); //This is where the exception occurs.*
}
}
When I run this code, I get the following error at the localScale line:
InvalidCastException: Cannot Cast from source type to destination type.
I can’t determine why an array of GameObjects would not be able to be edited as GameObjects. Thoughts?

pay more attention to code. exception should be raised one line higher.

Instantiate returns type of object that was given to it input.

You give to this method a Transform and try to cast returned object to GameObject.

so, give to input GameObject too or cast it to Transform on output.

using UnityEngine;
using System.Collections;
public class TestCodeCS : MonoBehaviour
{
    public int numSelectors = 5;
    public GameObject[] selectorArr;
    public GameObject selector; //selected in the editor
    void Start()
    {
        selectorArr = new GameObject[numSelectors];
        for (int i = 0; i < numSelectors; i++)
        {
            GameObject go = Instantiate(selector, new Vector3((float)i, 1, 0), Quaternion.identity) as GameObject;
            go.transform.localScale = Vector3.one;
            selectorArr *= go;*
 *}*
 *}*
*}
*

Your code was fine except for the double-cast. Either use “(GameObject)” or “as GameObject”, not both. Let me know. Just browsing here.