How can I control all object in 1 script?

I am new to Unity and I tried to google for the answers but yet I cannot find what I really want.

I want to make the 2Dcard game.
I create the Prefab named “Card”.
In “Card” has Sprite Class + My script (eg. SetUVs(…));
I want to create 10 cards with the same PreFab and change UV point to make my cards show various pictures.

In hierarchy, I create gameobject named “ControlCard” then I added “Card” Prefab 10 times as its children. I also renamed all children such as Card1 , Card2…

For the code part

public class ControlScript : MonoBehaviour
{
GameObject card1;
GameObject card2;
// Use this for initialization
void Start () {

    card1 = GameObject.Find("Card1");
    card1.CallSpecificFunction(); <----- this is what I was stucked, 

//the specilfic function which I made My Script within My Prefab above cannot referenced

}

// Update is called once per frame
void Update () {

}

}

Thank you in advance for any helps

GameObject.Find is quite heavy and you can get in trouble when there are more than one object called the same. You can use it, but remember GameObject.Find will return a GameObject, not a reference to your attached script. You have to use GetComponent to get the attached script.

If every card have only one instance of your card-script you can use GetComponentsInChildren which gives you an array of all script instances of your children. So you have all your cards in one array and you get the script instance directly.

CardScript[] cards;
void Start()
{
    cards = GetComponentInChildren<CardScript>();
    foreach (CardScript card in cards)
        card.CallSpecificFunction();

` }

The other way would be:

void Start ()
{
    card1 = GameObject.Find("Card1");
    card1.GetComponent<CardScript>().CallSpecificFunction();
}

But watch out! getComponent is not that fast, so it’s better to store the direct references. If you use it only once at start it doesn’t matter but every frame can drop your framerate.


edit

I’m not a friend of arrays either, so i would go with a generic List like PaulUsu said.

using System.Collections.Generic;

List<CardScript> cards;
void Start()
{
    cards = new List<CardScript>(GetComponentInChildren<CardScript>());
    foreach (CardScript card in cards)
        card.CallSpecificFunction();

` }

Lists can be changed dynamically.

card1.SendMessage(“CallSpecificFunction”);

will call all functions with name CallSpecificFunction in all scripts that are attached to gameObject as component