I'm struggling with assigning unique attributes to prefab objects.

As a test for a much larger project, I’m creating five primitive cubes (prefabs) and want to assign each a unique “Name” and two unique numbers assigned at random…I plan to access and manipulate these from other scripts. I have no difficulty creating unique names and accessing them from other scripts. However, I’m stumped on how to assign the numbers. This is what I currently have although I’ve tried all sorts of things and have looked at many, many previous posts but I can’t seem to find one on point.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    public GameObject testCube;

    private int numCubes = 5;
    private int[] testArray = new int[2];

    void Start()
    {
        for (int i = 0; i < numCubes; i++)
        {
            Vector3 position = new Vector3(Random.Range(5f, 45f), .5f, Random.Range(5f, 45f));
            GameObject cloneCube = Instantiate(testCube, position, Quaternion.identity);
            cloneCube.gameObject.GetComponent<Renderer>().material.color = Color.green;

            string stringA = "Name:  ";
            string stringB = i.ToString();
            cloneCube.name = stringA + stringB + stringB + stringB;

            testArray[0] = Random.Range(20, 30);
            testArray[1] = Random.Range(20, 30);
        }
    }
}

I’ve been working on this for quite some time now. I’ve got the name to work but I’m still having trouble with the numbers.

Okay, I have figured out how to get the unique numbers I need. Now I just need to figure how to access them from my other scripts. Will work on this.

In order to access testArray from other scripts it must be public and not private.
Your script is working fine. Set the array as public and you will see in the inspector that each pretty green cube has generated an array of 2 random numbers. Be aware although that random selection does not guarantee that every cube will have an array with unique values. If you want to accomplish that you must have a public list of numbers in an other script and set every cube script to remove the numbers that have been selected from the list.

topthink - not sure if i’m on the right thread (i’m a t work and only have a minute), but someone solved my textmesh problem and it works: http://answers.unity.com/comments/1611286/view.html

good luck!