#Help with Random.Range error.

1 messages · Page 1 of 1 (latest)

honest cape
#

I'm trying to make one of the children of a specific object turn red. Said child needs to be random, however I ran into this extremely annoying error (which I actually keep on running into).

    private int HexagonCount;

    void Start()
    {
        HexagonDirectory = GameObject.Find("Hexagon Directory");

         for (int i = 0; i < HexagonCount; i++)
        {
            int randomChildId = Random.Range(0, HexagonDirectory.transform.childCount);
            Transform randomChild = HexagonDirectory.transform.GetChild(randomChildId);
        }

        randomChild.GetComponent<Image>().color = new Color32(189, 23, 23, 0);
    }```

This is my script, and on the ```int randomChildId``` line, I get an error saying "Random is an ambigous reference between UnityEngine.Random and System.Random". I couldn't find anything to fix this and I really want it to *stop* happening. Hope I can get some help.
(I used to do Unity everyday, but I just came back after a long break so I'm pretty rusty)
austere fern
#

The error is pretty clear.
Both UnityEngine and System implement a type called Random. Since you are using both of the aforementioned namespaces in your script, it creates an ambiguous reference.
Just get rid of one of the using statements, or fully qualify the type name to get rid of the error.

vestal crown
#

Or alias whichever Random class you are using.