What does an array get attached to?

Hi everybody. First post. I’m in my 4th week in a Java class. I have a good foundation in 3D and have built some levels in Unreal, although I never finished any of them.

I’d like to create a whack-a-mole game as a learning experience. I think I have some cool ideas to make it a unique experience… if I can manage to get the core gametype in place.

From what it seems, my “moles” should be stored in an array. I’m guessing a BuiltIn array? My real question is what would the array script get attached to? I’ve gotten as far as creating a script attached to a mole that will transform the mole down 1 unit when the assigned key is entered… big accomplishment! But I figure I need to get the moles to pop up and retreat systematically as a group before that script could be useful. I’ve searched through all the documentation I could find. Can someone point me in the right direction? Thanks!

It sounds like you’re going to end up having a script that controls some moles (and maybe a GUI). I would personally call this script MoleController or something like that…

You will have to attach it to some object in your scene. What you attach it to will depend on what kind of stuff is in your scene.

In our games we typically have a script that we call the GUI controller. It generally manipulates a group of meshes that get imported into our game as a Maya scene. Our GUI script usually has a few arrays that represent different items in the Maya scene.

To me, as a programmer, the Maya scene is basically a tree of models (or transforms). Since this is the group of objects that our GUI controller manipulates, we attach our GUI controller script to this Maya Scene / Model Tree in our Unity scene.

It’s pretty handy because it allows you to reference all the children of the Maya scene easily like this:

/* print the name of each child of the transform this script is attached to */

var allMyChildren : Transform [] = transform.GetComponenetsInChildren(Transform);

for ( var thisChild : Transform in allMyChildren ) {
	Debug.Log("this child's name: " + thisChild.name);
}

I’m not sure the same approach will apply to your game, but it’s some food for thought.

I’m sure others around here will have some better answers…

Thanks Jahroy,

Sorry for the delayed response. Schoolwork has gotten in the way of Unity. I had your suggestion up and running but ultimately decided it may not be best for my situation since I plan on having many different types of "moles"

What I've settled on is similar. I'm using a group of empty objects set in an array and prefabs for each type of mole (only 1 so far). I'm assigning the mole the transform of a random position in the array.

//Spawn the Mole
if (roundBreak >= 5.0){
    if (spawnTimer >= 3.0){

        //Select the null and set position
        randomMole = MoleTransformArray[Random.Range(0, 4)];
        var instNormalMole:GameObject;
        instNormalMole = Instantiate(Mole, randomMole.transform.position , Quaternion.identity);

        //Print information and reset timer
        print(randomMole.name);
        print(spawnTimer);
        spawnTimer = 0.0;
    }
}

}