choose a random object from deactivated objects

Here is the script i’m using to select a random object. It is from Choose random Gameobject from array? - Unity Answers It is choosing a random object just fine.

My objective is to deactivate the objects in the Awake function and then have one object be activated and spawned in the start function.

using UnityEngine;
using System.Collections;

public class spawn : MonoBehaviour

{

    GameObject[] spawnPoints;
	GameObject currentPoint;
	int index;

void Start()
{
	spawnPoints = GameObject.FindGameObjectsWithTag("City");
	index = Random.Range (0, spawnPoints.Length);
	currentPoint = spawnPoints[index];
	print (currentPoint.name);

}
}

I’m thinking about changing something with the index but I’m not sure what that would do. Any ideas?

GameObject.FindGameObjectsWithTag() does not find game objects that are deactivated. You have a couple of choices. If the list of ‘City’ objects is fixed at start, don’t deactivate them in Awake. Instead, get the list, and then deactivate them after getting the list.

spawnPoints = GameObject.FindGameObjectsWithTag("City");
foreach (GameObject go in spawnPoints) {
     go.SetActive(false);
}

A second solution would be to not deactivate them at all. Simply turn off specific scripts as necessary to make them appear deactivated:

renderer.enabled = false;
collider.enabled = false;
rigidbody.enabled = false;

To ‘reactive’ the object, just enable the components.

An inefficient choice would be to get a list of game objects including disabled objects, and cycle through the list…or a list of objects with a specific script.