Get GameObject (What's wrong here?)

I’ve tried to alter a material script to get game objects instead.

Not quite working as planned.

using UnityEngine;
using System.Collections;

public class RandomMaterial : MonoBehaviour {
   
    public GameObject[] gameObject;
    int current;

    // Use this for initialization
    void Start () {
    }
   
    // Update is called once per frame
    public void Switch () {
        current++;
        if (current >= gameObject.Length)
            current = 0;
        GetComponent<GameObject> = gameObject[current];
    }
}

Original Code

using UnityEngine;
using System.Collections;

public class RandomMaterial : MonoBehaviour {
   
    public Material[] materials;
    int current;

    // Use this for initialization
    void Start () {
    }
   
    // Update is called once per frame
    public void Switch () {
        current++;
        if (current >= materials.Length)
            current = 0;
        GetComponent<Renderer>().material = materials[current];
    }
}

game objects aren’t components, they are the things that components are attached to.

what are you trying to do?

So you want to get a gameobject from an array?
What do you want to do with it when you’ve got it - assign it to a variable?

Gameobjects cannot be components but instead they contain components. You call ‘GetComponent’ on a Gameobject.

Does this fit what you want?

using UnityEngine;
using System.Collections;
public class RandomMaterial : MonoBehaviour {
  
    public GameObject[] gameObject;
    int current;
    private GameObject selectedObject;

    // Use this for initialization
    void Start () {
    }
  
    // Update is called once per frame
    public void Switch () {
        current++;
        if (current >= gameObject.Length)
            current = 0;
       selectedObject = gameObject[current];
    }
}

Just a tip,always get the SharedMaterial and not the Material - otherwise you would make instances of said materials and break batching.