Search Unity

Creating an array of random objects in C #.

Discussion in 'Scripting' started by lucked, Apr 6, 2011.

  1. lucked

    lucked

    Joined:
    Jul 11, 2010
    Posts:
    111
    Personal'm wondering how to create an array and take the values ​​of the array and random selection if someone can help me. I have a piece of the system in javascript but I want to C # please if they can help me.

    Thanks.
     
  2. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    Here is an example that uses an array of strings.

    Code (csharp):
    1.  
    2. string[] stringArray = new string[] { "text1", "text2", "text3" };
    3.  
    4. string randomString = stringArray[Random.Range(0, stringArray.Length)];
    5.  
    Is that what you are looking for?